eNarc
asked on
Parsing String
Hi, I've got this function though its not what I'm wanting though it works great.
I like it to be something like
var
sl:tstringlist;
....
function Parse(String,Delimiter:str ing):strin g;
begin
...
result:=sl.text;
end;
is there a better way than the in the code. because I want to be able to do stuff with it
Parse('dsfdsfsdfdssd/ff/sd /fsd/f/sd/ fsd/f/sd/s f/s/df/sdf /sd/','/') ;
richedit1.lines.add(sl[3]) ;
I like it to be something like
var
sl:tstringlist;
....
function Parse(String,Delimiter:str
begin
...
result:=sl.text;
end;
is there a better way than the in the code. because I want to be able to do stuff with it
Parse('dsfdsfsdfdssd/ff/sd
richedit1.lines.add(sl[3])
Procedure ParseLastPart(const sl : TStrings; const value : string; const delimiter : string);
var
dx : integer;
ns,o : string;
txt : string;
delta : integer;
begin
delta := Length(delimiter) ;
txt := value + delimiter;
sl.BeginUpdate;
sl.Clear;
try
while Length(txt) > 0 do
begin
dx := Pos(delimiter, txt) ;
ns := Copy(txt,0,dx-1) ;
o:=ns;
sl.Add(ns) ;
txt := Copy(txt,dx+delta,MaxInt) ;
end;
finally
form1.RichEdit2.lines.add(o);
sl.EndUpdate;
end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your function will be
function Parse(Text:string; Index: integer; Delimiter: char): string;
var sl: TStringList;
begin
sl := TStringList.Create;
try
sl.Text := Text;
ExtractStrings([Delimiter], [' '], Pchar(Text), sl);
Result := sl[Index];
finally
sl.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
richedit1.lines.add(Parse('dsfdsfsdfdssd/ff/sd/fsd/f/sd/fsd/f/sd/sf/s/df/sdf/sd/', 3, '/'));
end;
ASKER
When I use StringList.Delimiter:= '/'; it also splits the spaces too? "5/5444 stfgvg /ughggg //56666 fghhh gggg/"
That's why you need to set StrictDelimeter := True.
ASKER
i can't seem accept the 2 comments.
Click the ACCEPT MULTIPLE SOULTIONS link and follow the instructions
mlmcc
mlmcc
Open in new window