Jump to content

Parsing TStrings!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
SirStorm25

SirStorm25

    Newbie

  • Members
  • Pip
  • 9 posts
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.

#2
SirStorm25

SirStorm25

    Newbie

  • Members
  • Pip
  • 9 posts
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.