Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing Text with StringList: \n vs #13#10 vs sLineBreak

I'm trying to parse a string with a TStringList:

  sl:=TStringList.Create;
  try
    sl.Text:=aString;
    FFirstRow:=sl[0];
    FSecondRow:=sl[1];
  finally
    sl.Free;
  end;

If aString:='aa'+#13#10+'bb' or aString:='aa'+sLineBreak+'bb' then FFirstRow is aa and FSecondRow is bb. But if aString:='aa\nbb'then FFirstRow gets the whole string (and there is no second row). How do I parse the string with \n as a delimiter?

I tried sl.Delimiter:=Char(13) (and sl.DelimitedText:=aString).

like image 875
Al C Avatar asked Nov 25 '25 15:11

Al C


1 Answers

You can just change the string that is treated as the line break in a TStringList:

  sl := TStringList.Create;
  try
    sl.LineBreak := '\n';
    sl.Text := aString;
    FFirstRow := sl[0];
    FSecondRow := sl[1];
  finally
    sl.Free;
  end;
like image 114
Uwe Raabe Avatar answered Nov 27 '25 05:11

Uwe Raabe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!