Results 1 to 3 of 3

Thread: String function - I forgot which one

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 1999
    Location
    Brossard, Québec, Canada
    Posts
    241
    Hi.
    I forgot which string function will return the number of times the word "the" was found in the string "the lion is the king of the jungle".

    thanks

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Canada
    Posts
    264

    Cool

    I never new about this function , but you can make one like:

    Private Sub Form_Load()
    MsgBox returnThe("the lion is the king of the jungle")
    End Sub

    Private Function returnThe(theString As String) As Integer
    Dim counter
    counter = 0
    Do
    place = InStr(theString, "the")
    theString = Right(theString, Len(theString) - place)
    If place <> 0 Then counter = counter + 1
    Loop While place <> 0
    returnThe = counter
    End Function
    In the beginning the universe was created. This has made a lot of people very angry and is generally regarded as a bad idea.

    - Douglas Adams
    The Hitchhiker's Guide to the Galaxy

  3. #3
    Guest
    I dont know if there is a function but here is some code i modified to do the same job. Hope it helps.
    [/CODE]
    Dim x As Integer
    Dim string1 As String
    Dim string2 As String
    Dim count As Integer

    string1 = "the lion is the king of the jungle"
    string2 = "the"
    x = 1
    count = 0

    Do Until x = 0
    x = InStr(x, string1, string2, 1)
    If x > 0 Then
    count = count + 1
    x = x + 1
    End If
    Loop

    MsgBox count
    [/CODE]

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