Count number of words using vb.net

Pluralsight Free Trial

LinkedIn Premium uses PayScale to estimate job salaries


Premium (Not Free) Video Tutorials

Free Video Tutorials & Free Tools

 

In this short tutorial I will show you how can we calculate the number of words in a string .

The string can be a string from inputbox or textbox or any string .

It is  useful because we may need to count the number of words a user may enter.

We have a function in .net called string.split.

Returns a string array that contains the substrings in this instance that are delimited by elements of a specified Unicode character array.

Vb.net code

 

 

Dim text As String = InputBox("enter some text")

Dim words() As String = text.Split" charracters")

MsgBox(words.Length &

" charracters")

Thanks Hopes it helps !!!

Remember you can use the same method in other .net languages also.

Related posts:

  1. String.Split Example – JavaScript Syntax – JS String.Split Sample Example String.Split Example - JavaScript Syntax - JS String.Split Sample Example...
  2. vb competition I recently went to a vb competition and i was...
  3. String.CharCodeAt Example: JavaScript Syntax – JS String.CharCodeAt Example String.CharCodeAt Example: JavaScript Syntax - JS String.CharCodeAt Example...
  4. String Example – Data Type – JavaScript Syntax – JS String Example String Example - Data Type - JavaScript Syntax - JS...
  5. String.CharAt Example: JavaScript Syntax – JS String.CharAt Example String.CharAt Example: JavaScript Syntax - JS String.CharAt Example...

Related posts brought to you by Yet Another Related Posts Plugin.

Comments

One Response to “Count number of words using vb.net”
  1. Khunkhar says:

     Dim word, a As String
            Dim b, i, count As Byte
            word = txtsentence.Text
            a = word.Trim
            b = a.Length
            count = 0
            For i = 0 To (b – 1)
                If a.Substring(i, 1) <> " " Then
                    count = count + 1
                End If

            Next
            lblnow.Text = count

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Powered by WP Hashcash

This blog uses the cross-linker plugin developed by Web-Developers.Net