Author | Message | Time |
---|---|---|
Networks | 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? | June 23, 2004, 2:57 PM |
Lenny | Be more specific, exactly what do you want out of the parsed information? | June 23, 2004, 3:06 PM |
Networks | 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. | June 23, 2004, 3:13 PM |
Lenny | 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. | June 23, 2004, 3:26 PM |
CrAz3D | I think an example would help us all figure it out. | June 23, 2004, 3:48 PM |
Eli_1 | 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. | June 23, 2004, 5:06 PM |
Tuberload | [quote author=Networks link=board=31;threadid=7405;start=0#msg66817 date=1088003602] 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. [/quote] 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): [code]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; }[/code] Now this will only search for one character at a time, but you could easily modify it to find whole strings. | June 23, 2004, 6:06 PM |
Newby | [code]Dim I as Integer For I = 0 to Len(String) 'Each character is Mid$(String, I, 1) Next I[/code] | June 23, 2004, 9:21 PM |
Stealth | You will want to start the For loop at 1. Mid() is not zero-based. | June 23, 2004, 10:17 PM |
Networks | [quote author=Newby link=board=31;threadid=7405;start=0#msg66869 date=1088025695] [code]Dim I as Integer For I = 0 to Len(String) 'Each character is Mid$(String, I, 1) Next I[/code] [/quote] Is what I used and it works. | June 24, 2004, 2:33 PM |
Eli_1 | Eeek, then you're using On Error Resume Next - Shame. :P | June 24, 2004, 5:29 PM |
BinaryzL | [quote author=Newby link=board=31;threadid=7405;start=0#msg66869 date=1088025695] [code]Dim I as Integer For I = 0 to Len(String) 'Each character is Mid$(String, I, 1) Next I[/code] [/quote] 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????) | June 24, 2004, 11:18 PM |
Newby | [quote author=Stealth link=board=31;threadid=7405;start=0#msg66883 date=1088029032] You will want to start the For loop at 1. Mid() is not zero-based. [/quote] I was deciding on putting 0 or 1. I figured I'd put 0 to be safe =P. | June 24, 2004, 11:30 PM |