From: "Peter Below (TeamB)" <100113.1101@compuXXserve.com> Subject: Re: strings Date: 24 May 2000 00:00:00 GMT Message-ID: Content-Transfer-Encoding: 8bit References: <8ggb1h$gn85@bornews.borland.com> Content-Type: text/plain; charset=iso-8859-1 X-Trace: 24 May 2000 13:08:38 -0800, 62.224.88.8 Organization: TeamB Mime-Version: 1.0 Reply-To: 100113.1101@compuXXserve.com Newsgroups: borland.public.delphi.objectpascal In article <8ggb1h$gn85@bornews.borland.com>, Baier Christoph wrote: > Does Delphi support a function (or exists a unit) who extracts substrings, > which are separated by spaces, f.e. to extract the substrings 'ARG1' and > 'ARG2' of the string 'PROGRAM ARG1 ARG2' . > {+------------------------------------------------------------ | Function IScan | | Parameters: | ch: Character to scan for | S : String to scan | fromPos: first character to scan | Returns: | position of next occurence of character ch, or 0, if none | found | Description: | Search for next occurence of a character in a string. | Error Conditions: none | Created: 11/27/96 by P. Below +------------------------------------------------------------} Function IScan( ch: Char; Const S: String; fromPos: Integer ): Integer; Var i: Integer; Begin Result := 0; For i := fromPos To Length(S) Do Begin If S[i] = ch Then Begin Result := i; Break; End; { If } End; { For } End; { IScan } {+------------------------------------------------------------ | Procedure SplitString | | Parameters: | S: String to split | separator: character to use as separator between substrings | substrings: list to take the substrings | Description: | Isolates the individual substrings and copies them into the | passed stringlist. Note that we only add to the list, we do | not clear it first! If two separators follow each other directly | an empty string will be added to the list. | Error Conditions: | will do nothing if the stringlist is not assigned | Created: 08.07.97 by P. Below +------------------------------------------------------------} Procedure SplitString( Const S: String; separator: Char; substrings: TStringList ); Var i, n: Integer; Begin If Assigned( substrings ) and ( Length( S )>0 ) Then Begin i:= 1; Repeat n := IScan( separator, S, i ); If n = 0 Then n:= Length( S )+1; substrings.Add( Copy( S,i,n-i )); i:= n+1; Until i>Length( S ); End; { If } End; { SplitString } Peter Below (TeamB) 100113.1101@compuserve.com) No e-mail responses, please, unless explicitly requested!