rafaelrgl
asked on
separeting string 01:00:00#$#PG#$#4#$# adsf fasdf
i would like to separete this:
01:00:00#$#PG#$#4#$# adsf fasdf
to this
01:00:00
PG
4
adsf fasdf
how will be the function inside a loop, then each time will get one line
01:00:00#$#PG#$#4#$# adsf fasdf
to this
01:00:00
PG
4
adsf fasdf
how will be the function inside a loop, then each time will get one line
ASKER
can you make this function looks like this, i'm getting a error on this line: output[high(output)] := input;
var
index : integer;
input, output : string;
begin
BD.DSCommandOut.DataSet.Op en;
BD.Query_CommandOut.First;
While not BD.Query_CommandOut.Eof Do
begin
input := BD.Query_CommandOutDESCRIC AO.Text;
SetLength(output, 0);
repeat
SetLength(output, length(output) + 1);
index := Pos('#$#', input);
if index = 0 then begin
output[high(output)] := input;
input := '';
end else begin
result[high(output)] := Copy(input, 1, index - 1);
input := Copy(input, index + 3, length(input));
end;
showmessage(output); // here i will handle
until input = '';
BD.Query_CommandOut.Next;
end;
end;
var
index : integer;
input, output : string;
begin
BD.DSCommandOut.DataSet.Op
BD.Query_CommandOut.First;
While not BD.Query_CommandOut.Eof Do
begin
input := BD.Query_CommandOutDESCRIC
SetLength(output, 0);
repeat
SetLength(output, length(output) + 1);
index := Pos('#$#', input);
if index = 0 then begin
output[high(output)] := input;
input := '';
end else begin
result[high(output)] := Copy(input, 1, index - 1);
input := Copy(input, index + 3, length(input));
end;
showmessage(output); // here i will handle
until input = '';
BD.Query_CommandOut.Next;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
var S:String;
begin
S:='01:00:00#$#PG#$#4#$# adsf fasdf';
ShowMessage(StringReplace( S,'#$#',#1 3#10,[rfRe placeAll]) ) ;
end;
var S:String;
begin
S:='01:00:00#$#PG#$#4#$# adsf fasdf';
ShowMessage(StringReplace(
end;
Sorry. i miss understood
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
TStrArray = array of string;
function SplitString(s : string) : TStrArray;
var
index : integer;
begin
SetLength(result, 0);
repeat
SetLength(result, length(result) + 1);
index := Pos('#$#', s);
if index = 0 then begin
result[high(result)] := s;
s := '';
end else begin
result[high(result)] := Copy(s, 1, index - 1);
s := Copy(s, index + 3, length(s));
end;
until s = '';
end;
procedure TForm1.FormCreate(Sender: TObject);
var
values : TStrArray;
n : integer;
begin
values := SplitString('01:00:00#$#PG
Memo1.Clear;
for n := 0 to length(values) - 1 do Memo1.Lines.Append(values[
end;