Results 1 to 2 of 2
  1. #1
    ppl2pass's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Posts
    804
    Reputation
    5
    Thanks
    111
    My Mood
    Amused

    [Vb.net] Count the # of "Hi" in a textbox?

    For example in my textbox1.text I have:
    Code:
    Hi my name is Hi. What is your name? Hi
    Msgbox will return 3.
    How can you do that?

  2. #2
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Hmm... ok I quickly wrote a regex function that splits all the words and then increments the length var when if finds the specified word. Here's the function, add it:

    Function FindLength( ByVal inputstring As String , ByVal wordtoFind As String )
    Dim f As String = inputstring
    Dim len As Integer = 0
    Dim w () As String = Regex.Split( f , "\W+",RegexOptions.IgnoreCase)
    If Not w .Length > 0 Then
    Exit Function
    End If
    For Each q As String In w
    If Not q = vbNullString Then
    If q = wordtoFind Then
    len + = 1
    End If
    End If
    Next
    Return len
    End Function


    Usage:

    MsgBox(FindLength( "Hi my name is Hi. What is your name? Hi", "Hi"))


    ^^ Returns '3'. Hope this helps ^_~

  3. The Following User Says Thank You to Hassan For This Useful Post:

    Blubb1337 (07-09-2010)

Similar Threads

  1. [Solved] [RSBOTS.NET] Installing the Bot Client
    By Sketchy in forum Runescape Help
    Replies: 4
    Last Post: 09-13-2011, 07:37 PM
  2. aIW Error: System.Net.WebException: The remote server returned an error :(404) Not...
    By ledwiston in forum Call of Duty Modern Warfare 2 Help
    Replies: 9
    Last Post: 01-28-2011, 10:58 AM
  3. Quote of the Week!
    By KING in forum General
    Replies: 27
    Last Post: 09-03-2010, 03:34 AM
  4. COUNT THE MEXICANS
    By Viibez in forum General
    Replies: 33
    Last Post: 06-19-2010, 02:57 PM
  5. QUOTE OF THE WEEK :|
    By IHelper in forum Spammers Corner
    Replies: 0
    Last Post: 01-09-2010, 08:12 AM