 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Brian C Famous Guest
|
Posted: Thu Sep 11, 2003 2:10 am Post subject: Finding next ';' in a string |
|
|
ok,
my eyes are blurry and my mind is slipping, and i can't think of how to do
this, but i know i've done it before.
i have a string in a list box which reads, for example:
0;0;123;44;0
or
0;1;21;456;90
basically variable length integers (each number could be between 1 and 3
digits) separated by semicolons (';')
what i'm trying to do, but can't even come close to figuring out is how to
find the next ';' in the string.
to put it simply, i want to retrieve the first number by recognizing that it
ends, because of the ';' and then reading the second number, etc...
thank you in advance.
--
brian
|
|
| Back to top |
|
 |
Ignacio Vazquez Guest
|
Posted: Thu Sep 11, 2003 2:17 am Post subject: Re: Finding next ';' in a string |
|
|
"Brian C Famous" <bfamous (AT) sentry-technology (DOT) com> wrote
| Quote: | what i'm trying to do, but can't even come close to figuring out is how to
find the next ';' in the string.
|
PosEx
Cheers,
Ignacio
|
|
| Back to top |
|
 |
Brian Cook Guest
|
Posted: Thu Sep 11, 2003 2:50 am Post subject: Re: Finding next ';' in a string |
|
|
PosEx? Is that something that comes with Delphi7?
- Brian
|
|
| Back to top |
|
 |
Nick Hodges (TeamB) Guest
|
Posted: Thu Sep 11, 2003 2:52 am Post subject: Re: Finding next ';' in a string |
|
|
Brian,
Give this a look --
function ParseToken(const S: String; var FromPos : integer ;Delimiter:
char): String;
var i, FoundPos: Integer;
begin
FoundPos := Length( S ) + 1 ;
for i := FromPos to Length( S ) do if S[ i ] = Delimiter then begin
FoundPos := i ;
break ;
end ;
Result := Copy( S, FromPos, FoundPos - FromPos);
FromPos := FoundPos + 1 ;
end;
Nick Hodges - TeamB
Lemanix Corporation
Please always follow the newsgroup guidelines --
http://www.borland.com/newsgroups
|
|
| Back to top |
|
 |
Kjell Rilbe Guest
|
Posted: Thu Sep 11, 2003 10:00 am Post subject: Re: Finding next ';' in a string |
|
|
*LOL* Wow! And here I have been doing this all these years:
MyStrList.Text:=StringReplace('0;0;123;44;0',';',#13#10,[rfReplaceAll]);
Silly me! :-)
Thanks!
Kjell
Andrew Fiddian-Green skrev:
| Quote: |
Delphi's TStringList has all the features you need for parsing delimited lists:
strlist := TStringList.Create;
strlist.Delimiter := ';';
strlist.DelimitedText := '0;0;123;44;0';
for i := 0 to pred(strlist.Count) do
begin
doDomethingWith(strlist.Strings[i]);
end;
Regards,
AndrewFG
"Brian C Famous" <bfamous (AT) sentry-technology (DOT) com> wrote
ok,
my eyes are blurry and my mind is slipping, and i can't think of how to do
this, but i know i've done it before.
i have a string in a list box which reads, for example:
0;0;123;44;0
or
0;1;21;456;90
basically variable length integers (each number could be between 1 and 3
digits) separated by semicolons (';')
what i'm trying to do, but can't even come close to figuring out is how to
find the next ';' in the string.
to put it simply, i want to retrieve the first number by recognizing that it
ends, because of the ';' and then reading the second number, etc...
thank you in advance.
--
brian
|
--
---------------------------------------------------------------------------
Kjell Rilbe
Home: +46 8 7610734
Cell: +46 733 442464
---------------------------------------------------------------------------
"If there's a price for bein' me, that's one I'll have to pay"
Aaron Tippin
---------------------------------------------------------------------------
|
|
| Back to top |
|
 |
Ignacio Vazquez Guest
|
Posted: Thu Sep 11, 2003 1:31 pm Post subject: Re: Finding next ';' in a string |
|
|
"Brian Cook" <bcook@rowdydogsoftware[REMOVE].com> wrote in message
[email]MPG.19c99ef690f85d2a989735 (AT) newsgroups (DOT) borland.com[/email]...
| Quote: | PosEx
PosEx? Is that something that comes with Delphi7?
|
It's found in D7, not certain about other versions. From the D7 help file:
"""
Unit
StrUtils
Delphi syntax:
function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;
Description
PosEx returns the index of SubStr in S, beginning the search at Offset. If
Offset is 1 (default), PosEx is equivalent to Pos.
PosEx returns 0 if SubStr is not found, if Offset is greater than the length
of S, or if Offset is less than 1.
"""
Cheers,
Ignacio
--
No, don't send me e-mail directly. No, just don't.
|
|
| Back to top |
|
 |
Brian Cook Guest
|
Posted: Thu Sep 11, 2003 4:11 pm Post subject: Re: Finding next ';' in a string |
|
|
| Quote: | PosEx
PosEx? Is that something that comes with Delphi7?
It's found in D7, not certain about other versions. From the D7 help file:
|
Thanks.
- Brian
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|