Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STUCK......WITH.......strlcopy(),

Status
Not open for further replies.

MARTINRODDY

Programmer
Apr 3, 2001
30
US
Hi,

I am using strlcopy(buffer,PChar(job_array[kount].oper_id),oper_pos));

to extract a substring from a string

e.g.
20001,20002,20003,20004

I want to get 20002 from this string ???

The above code works for the first substring. But can i use it to move into the string and extract a value ???? If not then is there any other way possible.

Thanks for any help at all
Martin
 
The second parameter for StrLCopy is a pchar, so technically you can point that to a different point in the string, if that makes sense.

Why are you stuck with strlcopy anyway? I usually like to parse a string like that into a stringlist of tokens. Here is the code I use to do that:

{ParseString}
procedure ParseString(str, delimiter: string; tokens: TStringList);
var firstchar, lastchar: Longint;
token: string;
begin
tokens.Clear;
if str='' then
Exit;
firstChar := 1;
while Pos(delimiter, str)> 0 do
begin
lastChar := Pos(delimiter, str) -1;
token := Copy(str, firstchar, lastchar-firstChar+1);
firstChar := Pos(delimiter, str) +1;
str[firstchar-1] := chr(286);
tokens.Add(Trim(token));
end;
token := Copy(str, firstchar, Length(str)-firstchar+1);
tokens.Add(trim(token));
end;
 
Just use a TStringList

sl := TStringlist.Create;
sl.CommaText := 20001,20002,20003,20004;

for i := 0 to sl.Count-1 do begin
ShowMessage(sl);
end;

that's it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top