|
-
Jan 21st, 2000, 07:58 AM
#1
Thread Starter
New Member
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!
-
Jan 21st, 2000, 08:19 AM
#2
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).]
-
Jan 21st, 2000, 09:51 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|