Link to home
Start Free TrialLog in
Avatar of rafaelrgl
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

 
Avatar of ZhaawZ
ZhaawZ
Flag of Latvia image

type
  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#$#4#$# adsf fasdf');
Memo1.Clear;
for n := 0 to length(values) - 1 do Memo1.Lines.Append(values[n]);
end;
Avatar of rafaelrgl
rafaelrgl

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.Open;
   BD.Query_CommandOut.First;
   While not BD.Query_CommandOut.Eof Do
   begin
      input := BD.Query_CommandOutDESCRICAO.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;
Avatar of dinilud
procedure TForm1.Button1Click(Sender: TObject);
var S:String;
begin
  S:='01:00:00#$#PG#$#4#$# adsf fasdf';
  ShowMessage(StringReplace(S,'#$#',#13#10,[rfReplaceAll])) ;
end;

Sorry. i miss understood
ASKER CERTIFIED SOLUTION
Avatar of dinilud
dinilud
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial