Results 1 to 2 of 2

Thread: Calculating amount of words?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Location
    My computer
    Posts
    3

    Calculating amount of words?

    Can someone please tell me how I can calculate the amount of words as the end-user is typing in a textbox and the amount to appear in a label? Thanks in advance.
    I use Visual Basic .NET standard version

  2. #2
    Hyperactive Member Bananafish's Avatar
    Join Date
    Jan 2001
    Posts
    394

    Re: Calculating amount of words?

    Probably not the most elegant solution, and you should almost definitely be using a stringbuilder if the string involved is any great length, but if you add something like this code to the textchanged event of teh text box, it will be a good start...

    VB Code:
    1. Dim strText As String
    2.         strText = txtWords.Text.Replace(",", " ")
    3.         strText = strText.Replace(".", " ")
    4.         strText = strText.Replace(";", " ")
    5.         Dim strWords() As String = strText.ToString.Split(" "c)
    6.         Dim intWords As Int32
    7.         For intWord As Int32 = 0 To strWords.Length - 1
    8.             If strWords(intWord).Trim <> "" Then intWords += 1
    9.         Next
    10.        lblWords.Text="Count:" & intWords.ToString

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width