Perhaps not ideal, in that you can still face the age old problem of what
happens if your separator character ends up included in the string.
Better to use a stream format like Length of string followed by string
contents. You could perhaps include a count at the front of the number of
strings in the packet also.
Myles.
> -----Original Message-----
> From: Matt Powell [SMTP:[EMAIL PROTECTED]]
> Sent: Tuesday, 18 April 2000 23:28
> To: Multiple recipients of list delphi
> Subject: Re: [DUG]: Packing Problem
>
> > Just another newbie lack-of-knowledge problem:
> > What is the best way to communicate a bunch of strings through udp?
> > I thought of concatenating them altogether with some symbol between (say
> &),
> > but how would I go about unpacking it?
>
> procedure UnpackString(S: String; Sym: Char; StrList: TStrings);
> var
> s2: String;
> begin
> s2 := '';
> while s <> '' do
> begin
> if s[1] = Sym then
> begin
> StrList.Add(s2);
> s2 := '';
> Delete(s, 1, 1);
> end else
> begin
> s2 := s2 + s[1];
> Delete(s, 1, 1);
> end;
> end;
> StrList.Add(s2);
> end;
>
> S is the packed string, Sym is the separator, and StrList is a (probably
> empty) TStrings instance. For example:
>
> UnpackString('This&is&a&test', '&', Memo1.Lines);
>
> All code 100% untested (written in OE ;), but it should work OK.
>
> HTH,
> - Matt
>
>
>
> --------------------------------------------------------------------------
> -
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz