SL : TStringList;
SL := TStringList.create;
SL.Text := DataString;
DataString := '';
for i := 0 to SL.Count - 1 do
DataString := DataString + SL.Strings[i] + ';';
SL.Free;
Not as neat but a heck of a lot more accurate.
Mark
Chris Birmele wrote:
>
> I am trying to convert a string, substituting CR/LF for semicolons
> using the following code:
>
> while Pos(#13#10, DataString) > 0 do
> DataString[Pos(#13#10, DataString)] := ';';
>
> It does almost the right thing (see actual result), but I would have
> expected a string without any linefeeds (see expected result). What
> am I doing wrong here?
>
> Thanks, Chris
>
> - actual result
>
> line1;
> line2;
> line3
>
> - expected result
>
> line1;line2;line3
You are replacing one char with another, not two chars with one char.
Mike Orriss (m...@3kcc.co.uk)
http://www.3kcc.co.uk/notetree.htm
> I am trying to convert a string, substituting CR/LF for semicolons
> using the following code:
>
> while Pos(#13#10, DataString) > 0 do
> DataString[Pos(#13#10, DataString)] := ';';
>
> It does almost the right thing (see actual result), but I would have
> expected a string without any linefeeds (see expected result). What
> am I doing wrong here?
The #13 gets replaced, but the #10 does not. Basically,
it is still there.You would need to use some loop to check
for #13, with a read-ahead buffer to check that the next
character is a #10 - then you replace one, and delete the
other.
I once wrote a quick and dirty DOS program to convert
unix text files to DOS format and vice versa. The program
contains a function which does something similar to what
you are seeking to do here (replacing #13#10 with a #10).
I have recently updated it to compile for GNU Pascal, and
it will be released as an example program for the next
version of GNU Pascal. It compiles quite fine as a console
application under D2 and D3, and the function can easily be
modified for your purposes. If you are interested, you can
mail me (my email address is below), and I will send you
a copy.
Best regards, The Chief
--------
Dr. Abimbola A. Olowofoyeku (The African Chief)
Email: la...@keele.ac.uk
Homepage: http://ourworld.compuserve.com/homepages/African_Chief/
Author of: Chief's Installer Pro 4.52 for Win16 and Win32
ftp://ftp.simtel.net/pub/simtelnet/win3/install/chief452.zip
while Pos(#13#10, DataString) > 0 do begin
i := Pos(#13#10, DataString);
Delete(DataString,i,2);
Insert(';',DataString,i);
end;
Jerry
Chris Birmele wrote:
> I am trying to convert a string, substituting CR/LF for semicolons
> using the following code:
>
> while Pos(#13#10, DataString) > 0 do
> DataString[Pos(#13#10, DataString)] := ';';
>
> It does almost the right thing (see actual result), but I would have
> expected a string without any linefeeds (see expected result). What
> am I doing wrong here?
>
Jerry S.L. Phang wrote in message <362B9DFF...@pc.jaring.my>...