Here is a function that makes parsing strings in DBP a peice of cake without the use of TPCs.
All you have to do is call the function like so:
mystg$="milk,eggs,cheese,bacon"
a=parsestring(mystg$,",")
The first argument of the function is the string you wish to parse, and the second argument is the delimeter you want to use to seperate the parts. In this case, we use the comma as the delimter, so the function will return an array of elements, and the bounds of the array will be the number of items found:
a(0)=milk
a(1)=eggs
a(2)=cheese
a(3)=bacon
You can use any character as a delimter including the space " ", which makes it handy for parsing plain lines of text.
so if you passed "Why did the chicken cross the road?" like so:
a=parsestring("Why did the chicken cross the road?"," ")
the function would return:
a(0)="Why"
a(1)="did"
....
a(6)="road?"
Hope this helps you in your programming endeavors!
The function:
function parsestring(stringtoparse as string, delim as string)
dim a(200)
s As String
DelimPos As Integer
count As Integer
If Len(StringToParse) = 0 Or Len(Delim) = 0
ParseString = Null
ExitFunction parsestring
EndIf
If Len(Delim) >= Len(StringToParse)
ParseString = Null
ExitFunction parsestring
EndIf
DelimPos = InStr(StringToParse, Delim,1)
If DelimPos = 0
a(0) = StringToParse
ParseString = a
ExitFunction parsestring
EndIf
s = StringToParse
count = 0
lpp:
a(count) = Left$(s, DelimPos - 1)
s = Right$(s, Len(s) - (DelimPos + Len(Delim) - 1))
count = count + 1
DelimPos = InStr(s, Delim,1)
If DelimPos = 0
a(count) = s
s = ""
EndIf
if Len(s) <> 0 then goto lpp:
ParseString = a
EndFunction parsestring