Calcyman,
A little tip, If you're planning upon parsing a lot of strings, then there's a few bottle necks in it given how DBpro works. One easy opt, is to precalc the length of A$ outside of the parsing loop. From memory Dbpro evaluates the destination expression in FOR/NEXT loops each iteration. So the expression
For i = 1 to len(a) means that for each time we step through the loop Db is resolving the string length of A. Now from what i can tell, A never changes, therefore it's length never changes so we can precalculate it's that and just substitute it back in.
A bit like this (snippet untested!)
print breakdown( "Surname = Johnson, Name = Fred, Age = 65, Height = 6 feet", "Name" )
wait key
end
function breakdown(a as string, query as string)
a = a + ",null=0"
b as integer
i as integer
c as integer
part as string
qreturn as string
LengthOfA=LEN(a)
Do
c = 0
For i = 1 to LengthOfA
If MID$(a,i)="," then c = i : exit
Next i
If c=0 then c=LengthOfA+1
part = LEFT$(a,c-1)
If LEN(part)<LengthOfA then a = RIGHT$(a,LengthOfA-LEN(part)-1)
If LEFT$(part,1)=" " then part=RIGHT$(part,LEN(part)-1)
If left$(part,LEN(query)+1)=query+"=" or left$(part,LEN(query)+2)=query+" ="
part=RIGHT$(part,LEN(part)-LEN(query))
If LEFT$(part,1)=" " then part=RIGHT$(part,LEN(part)-1)
If LEFT$(part,1)="=" then part=RIGHT$(part,LEN(part)-1)
If LEFT$(part,1)=" " then part=RIGHT$(part,LEN(part)-1)
If RIGHT$(part,1)=" " then part=LEFT$(part,LEN(part)-1)
b = 1 : qreturn = part
endif
If LEN(part)=>LengthOfA-1 or b = 1 then exit
Loop
endfunction qreturn
Another little tip is that string comparisons are pretty heavy. So when comparing for individual characters, it's generally best to grab a chr as ASC II value then compare it with the CHR values. Ie
ThisChr=mid(SomeString$,lp)
if ThisCHR=32 then Print "Space"
if ThisCHR=61 then Print "Equals"
etc