Results 1 to 3 of 3

Thread: Finding Characters

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Posts
    9

    Post

    If I have a string of text called Ystring, and I want to figure out if there are any a's in the whole string, how do I find that out.
    Let's say the string is:
    "Monkeys are animals"
    I want the function to tell me that there are three a's, or one y, or two m's in the string. Please help me. I need to know how to do this!

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Here is something that will work. You would be better off changing the three almost identical loops into a function that would return the count of the search character passed to it.
    Code:
        Dim intPos As Integer
        Dim intACount As Integer
        Dim intYCount As Integer
        Dim intMCount As Integer
        
        intPos = 1
        Do While InStr(intPos, UCase(Ystring), "A")
          intPos = InStr(intPos, UCase(Ystring), "A") + 1
          intACount = intACount + 1
        Loop
        
        intPos = 1
        Do While InStr(intPos, UCase(Ystring), "M")
          intPos = InStr(intPos, UCase(Ystring), "M") + 1
          intMCount = intMCount + 1
        Loop
        
        intPos = 1
        Do While InStr(intPos, UCase(Ystring), "Y")
          intPos = InStr(intPos, UCase(Ystring), "Y") + 1
          intYCount = intYCount + 1
        Loop
        
        MsgBox "There are " & intACount & " a's, " _
                            & intYCount & " y's, and " _
                            & intMCount & " m's"
    ------------------
    Marty
    Can you buy an entire chess set in a pawn shop?




    [This message has been edited by MartinLiss (edited 01-21-2000).]

  3. #3
    Guest

    Post

    you can use the mid function.
    to get the fourth letter i believe you would do in this format mid(stringname, startingpoint, length to take)
    so you would do Mid(StrName, 4, 1) that will get you the fourth letter.
    if you do Mid(StrName, x, 1) it in a for loop from 1 to string length for the x you will go through each letter.

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