• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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

 
0
rafaelrgl
Asked:
rafaelrgl
  • 3
1 Solution
 
ZhaawZSoftware DeveloperCommented:
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;
0
 
rafaelrglAuthor Commented:
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;
0
 
diniludCommented:
procedure TForm1.Button1Click(Sender: TObject);
var S:String;
begin
  S:='01:00:00#$#PG#$#4#$# adsf fasdf';
  ShowMessage(StringReplace(S,'#$#',#13#10,[rfReplaceAll])) ;
end;

0
 
diniludCommented:
Sorry. i miss understood
0
 
diniludCommented:
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;
      While input<>'' do
      begin
         index := Pos('#$#', input);
         if index = 0 then index:=length(input);
         output := Copy(input, 1, index - 1);
         input := Copy(input, index + 3, length(input));
         showmessage(output);  // here i will handle
      end;
      BD.Query_CommandOut.Next;
   end;
end;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now