What's the best way to parse each letter in a sentence or word? Feanor told me a loop would be best from 0 to len(string) is there any other way?
Be more specific, exactly what do you want out of the parsed information?
I want to see if that letter is inside another string.
BTW: Instr() won't work if I have to multiple letters for what I am doing.
Are you trying to find the occurence of a series of letters in a string?
If that case, Instr() will work...I'm still uncertain as what you are trying to do.
I think an example would help us all figure it out.
We're obviously having a misunderstanding. Either you're confused because you don't know InStr will return the FIRST occurance of something, regardless of how many there are, or we're confused and don't understand the question.
Quote from: Networks on June 23, 2004, 10:13 AM
I want to see if that letter is inside another string.
BTW: Instr() won't work if I have to multiple letters for what I am doing.
Perform a linear search.
Algorithm:
1) Set a location variable to 0.
2) Loop through the char array (string) until you come accrossed the desired element (char) or the end of the array.
2b) increment the location variable.
3) if location equals the length of the char array, set it to -1
4) return the location variable
This will produce either -1 if the character is not found, or the location of the character.
Example (java):
public static int linearSearch (char[] source, char element)
{
int location = 0;
while ((source[location] != element) && (location < source.length))
location++;
if (location == source.length)
location = -1;
return location;
}
Now this will only search for one character at a time, but you could easily modify it to find whole strings.
Dim I as Integer
For I = 0 to Len(String)
'Each character is Mid$(String, I, 1)
Next I
You will want to start the For loop at 1. Mid() is not zero-based.
Quote from: Newby on June 23, 2004, 04:21 PM
Dim I as Integer
For I = 0 to Len(String)
'Each character is Mid$(String, I, 1)
Next I
Is what I used and it works.
Eeek, then you're using On Error Resume Next - Shame. :P
Quote from: Newby on June 23, 2004, 04:21 PM
Dim I as Integer
For I = 0 to Len(String)
'Each character is Mid$(String, I, 1)
Next I
That code will not work, like stealth said mid() starts from 1. (Plus why would you want on error resume next for a simple for loop????)
Quote from: Stealth on June 23, 2004, 05:17 PM
You will want to start the For loop at 1. Mid() is not zero-based.
I was deciding on putting 0 or 1. I figured I'd put 0 to be safe =P.