Joel,

const
  MAXELEMENT = 100;
var
  s: string;
  a: array [1..MAXELEMENT] of string;
  i, p: Integer;
begin
  s := 'Happy|Birthday|to|you';
  i := 1;
  repeat
    // Find the next position of the delimiter character
    p := Pos ('|', s);
    if p = 0 then begin
      // Loop terminating condition
      a[i] := s;  // Assign remaining characters to next element
      Break;
    end else begin
      // Copy up to (but not including) delimiter into next element
      a[i] := Copy (s, 1, p-1);
      Inc(i);
      // Adjust the string
      s := Copy (s, p+1, Length(s));
    end;
  // Sanity check - so that we don't go past the array bounds.
  until i >= MAXELEMENT;
end;

I would use TStringList instead of an array;

var
  tsl: TStringList;
  s: string;
begin
  s := 'Happy|Birthday|to|you';
  // Replace all '|' with line breaks
  s := StringReplace (s, '|', #$0D#$0A, [rfReplaceAll]);
  // Create the object - remember to free it later and use a try - finally
block.
  tsl := TStringList.Create;
  // Read into the string list (line breaks are the default delimiters)
  tsl.Text := s;
end;

Hope this helps,
Dennis.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, 12 April 2001 15:35
> To: Multiple recipients of list delphi
> Subject: [DUG]: Parser
>
>
> A newbie question:
>
> How is it possible / what is the best way to turn a string containing
> 'special' characters into an array?
>
> IE : 'Happy|Birthday|to|you' becomes
> Happy
> Birthday
> to
> you
>
> (inside an array)
>
> TIA
> -Joel
>
> ------------------------------------------------------------------
> ---------
>     New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
>                   Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to