Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Parsing TStrings!

delphi string

  • Please log in to reply
1 reply to this topic

#1 SirStorm25

SirStorm25

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 04 October 2008 - 01:38 PM

Hi All!

I was wondering if the below is possible:

When the user clicks the button, the program takes all the text from Memo1.Lines and for each new line (in delphi, #13+#10) and replaces all new lines (#13+#10) with \line .

I have tried using the tutorial available on delphi.about.com:

procedure ParseDelimited(const sl : TStrings; const value : string; const delimiter : string) ;
var
   dx : integer;
   ns : 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) ;
       sl.Add(ns) ;
       txt := Copy(txt,dx+delta,MaxInt) ;
     end;
   finally
     sl.EndUpdate;
   end;
end;

but i'm no good with TStrings (confuses me ).

Any Ideas?

Regards
SirStorm25.
  • 0

#2 SirStorm25

SirStorm25

    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 04 October 2008 - 02:00 PM

Never-Mind! I found a fix, quite simple actually :D .


procedure TRTFFile.ParseDelimited(const S: TStrings; const Value: string; const Delimiter: string);
var
   Dx : integer;
   Ns : string;
   Txt : string;
   Delta : integer;
begin
   Delta := Length(Delimiter);
   Txt := Value + Delimiter;
   S.BeginUpdate;
   S.Clear;
   try
     while Length(Txt) > 0 do
     begin
       Dx := Pos(Delimiter, Txt);
       Ns := Copy(Txt,0,Dx-1);
       S.Add(Ns + '\line'); // Simply adds "\line" to the end of each parsed string.
       Txt := Copy(Txt,Dx+Delta,MaxInt);
     end;
   finally
     S.EndUpdate;
   end;
end;

Hope it helps anybody else who needs it ;)
Regards

SirStorm25.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download