count text Characters in vb.net

I have a question how would set vb.net to count text that is in a text box. I would like to call it from a class. This is what I have in my class but it returns zeros.

Imports System
Imports System.IO
Public Class StringProcessor
    Private numCharacters As Integer
    Private numWords As Integer
    Private numSentences As Integer
    Private numParagraphs As Integer
    Private StringData As String
    Public ReadOnly Property Characters() As Integer
        Get
            Return numCharacters
        End Get
    End Property
    Public ReadOnly Property Words() As Integer
        Get
            Return numWords
        End Get
    End Property
    Public ReadOnly Property Sentences() As Integer
        Get
            Return numSentences
        End Get
    End Property
    Public ReadOnly Property Paragraphs() As Integer
        Get
            Return numParagraphs
        End Get
    End Property

    Public Property StringContents() As String
        Set(ByVal Value As String)
            numCharacters = 0
            numWords = 0
            numSentences = 0
            numParagraphs = 0
        End Set
        Get
            Return StringData
        End Get
    End Property
End Class

This is what I have in my main form:

Imports Course
Imports System
Imports System.IO


    Private Sub btnAnalyzeText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnalyzeText.Click
        Dim pintText As New StringProcessor

        pintText.StringContents = txtFile.Text
        txtChars.Text = pintText.Characters.ToString()
        txtWords.Text = pintText.Words.ToString()
        txtSentences.Text = pintText.Sentences.ToString()
        txtParagraphs.Text = pintText.Paragraphs.ToString()
       
    End Sub
End Class


Thanks in advance for your help.
matrixninja2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dcgamesCommented:
This is obviously incomplete. In your StringContents() implementation you don't store the string data, nor do you count the chars, words, sentences or paragraphs.

Dave
0
matrixninja2Author Commented:
Thats the problem I am lost on how to add that data.
0
vippxCommented:
Hi,

you could write the logic for spearation in the set part of your string contents property.

The Number of characters is simple, just the Length of the string would give u that...

As for word count, u can use the String.Split() method to split the strings by the use of a delimiting character or multiple characters(plenty of examples in MSDN), which would be a space(" ") for standard text. If you need advanced processing, run a search for "string tokenizers for .NET" and you would have a few examples.

Sentence count also can be found by splitting the string using a delimiter as a "."

Paragraph count is could get tricky, but principle remains same, here try a split with vbNewLine constant which represents the newline character.

if u need more help let me know

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

matrixninja2Author Commented:
I am pretty new So I would not know how to even write that code.
0
dcgamesCommented:
I'm sorry but this sounds like homework to me and we're not supposed to give you the answer in detail.

What I can say is that you have a string passed in as a parameter and that string has a length, so it is fairly trivial to have a loop over the entire length of the string and look at each character.

Brute force will do the job, you don't have to be very sophisticated.

to get you started

            stringData = Value
            numCharacters = stringData.Length()
            numWords = 0
            numSentences = 0
            numParagraphs = 0
            doingWord=false

Now do a loop and look at every character. If it is a letter or digit, set a flag to indicate you are looking at a word. If it's anything else and you were looking at a word, then count a word and reset the flag.

If you see a period, you could assume sentence, I guess.

If you see a carriage return (or maybe a line feed), you could assume a paragraph.

And that's it.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vippxCommented:
Hi as dcgames rightly said, we can help you but coding it for u is not the purpose.

The string.split() is an easy way to tokenize strings. however if you wish to implment the approach from scratch like dcgames suggested, you should look up more information on text parsers. An important concept that would help you is the use of a lookahead character

That is when you loop through the string, u read a character and also the immediate next one, called the  look ahead character. and the combination of the read character and the lookahead, put it in a select case statement and see if u found characters like space, comma, semicolon, period etc which would denote end of a word.  

example most often current character being period( . ) and look ahead character being a space(" ") means you have reached the end of a sentence

if you hit a character as space(" ") and lookahead is also a spacwe(" ") you know there is an extra space and the next whitespace should be ignored.

Using similiar logic you can fine tune your parse the string the way you like.

hope this helps
0
matrixninja2Author Commented:
Thanks guys that did help me understand.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.