RE: Parse
"Glenn B. Lawler" <[email protected]> Sat, 16 Aug 2003 14:33:17 -0500
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
> Beginner - I am trying to find a simple way to parse the tree
> integers out of astring thats in the form of "Values are (10,123,13)"
>
> Any help would be appreciated.
>
> What I've come up so far is
> 1. use the "between" function from th ejedi library to get the three
> integers.
> 2. replace the "," with #13
> 3. add to riche edit component.
> 4. then use strto int for each of the three lines.
>
> I am sure ther is a simpler way.
Here's a straightforward way that only uses standard Delphi functions:
var
S,N: string;
P: integer;
S:='Values are (10,123,0)';
{Extract the numbers}
P:=pos('(',S);
Delete(S,1,P);
P:=pos(')',S);
Delete(S,P,Length(S));
{Scan each number from S}
while S>'' do begin
P:=pos(',',S);
if P=0
then begin
N:=S;
S:='';
end
else begin
N:=copy(S,1,Pred(P));
Delete(S,1,P);
end;
{Assert: N= a single number process it here}
ShowMessage(N);
end;
HTH,
Glenn Lawler
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/i7folB/TM
---------------------------------------------------------------------~->
Delphi VCL Top Sites!
http://www.sandbrooksoftware.com/TS/TS2/Components.shtml
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
---------------------------------------------------------------
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/