Has anyone developed a string parsing object ?
woodsmith
Posts: 1
I don’t want to have to reinvent the wheel if someone has already written code to parse text strings.· Specifically I need to find the location of one string inside another.· Example:
String to search: “this is a string”
String to search for: “is”
·
Desired·results: the string “is” starts at character 6 in the string “this is a string”
·
If anyone has built, worked on or is working on a similar piece of code I would like to see it.
·
I am not quite sure where to start.· I was thinking first convert the string into an array of characters, however, I am not sure how to do that.
Any help would be greatly appreciated!
Background:
I have two devices, device A sends an ASCII string to device B.· I am trying to put the prop in the middle to solve a buffering problem that device B has and to remove some of the unnecessary characters from the string.
String to search: “this is a string”
String to search for: “is”
·
Desired·results: the string “is” starts at character 6 in the string “this is a string”
·
If anyone has built, worked on or is working on a similar piece of code I would like to see it.
·
I am not quite sure where to start.· I was thinking first convert the string into an array of characters, however, I am not sure how to do that.
Any help would be greatly appreciated!
Background:
I have two devices, device A sends an ASCII string to device B.· I am trying to put the prop in the middle to solve a buffering problem that device B has and to remove some of the unnecessary characters from the string.
Comments
-Phil
Technically, "is" appears at index 3 in your sample string.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
(some "Spinish" pseudocode[noparse]:)[/noparse]
repeat n from 1 to string_length··········· ' finding string length left to the student... [noparse];)[/noparse]
· val1 := lookdown (mystring(n) :" ","i","s") ' note begining " " to skip the "is" in "this"
· val2 := lookdown (mystring(n+1):" ","i","s")
· val3 := lookdown (mystring(n+2):" ","i","s")
· if val1*100 + val2*10 + val3 == 123 'need to use magnitudes cuz " is" would = "s i" (index 4) and
····················································· ' "is " (index3) if you just added val's. All would = 3
··· do_stringfound(n+1) ' use n+1 to skip the space
Post Edited (Paul) : 3/15/2007 6:40:05 PM GMT
Actually it's index 2. The first index is 0.
Sorry I couldn't resist.
That's what I said....hey...where did that 3 come from??!!! ;^)
...I could have said it depends on the language...I've worked in various "business BASICs" that allow you to decide whether indexes start at 0 or 1...but I just goofed...sleepy after lunch, I guess...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...