From: marcov@turtle.stack.nl   
      
   On 2010-09-07, delo wrote:   
   >>snip   
   >   
   > why you need an array of strings? probably something of untold... if the   
   > need is only summarize the third field just use a large type a just   
   > totalize in it to isolate the third field you can use the pos function   
   > (unsure about it in fp) searching for a ',' unfortunately the pos function   
   > doesnt have a start position ( like basic) so you can simply delete the   
   > part of string to the first ',' then delete to the second ',' when you   
   > find the third ',' then copy the chars from 1 to position-1 and you have   
   > the third field, other consideration about lead or trail blanks.   
      
   Borland-like Pascal's got a pos with start in Delphi 7 called "POSEX". FPC   
   also has it.   
      
   FPC also has backwards versions (rpos,rposex) as well as set variants:   
      
   Function PosEx(const SubStr, S: string; Offset: Cardinal): Integer;   
   Function PosEx(const SubStr, S: string): Integer;inline; // Offset: Cardinal= 1   
   Function PosEx(c:char; const S: string; Offset: Cardinal): Integer;   
      
      
   Function RPosEX(C:char;const S : AnsiString;offs:cardinal):Integer; overload;   
   Function RPosex (Const Substr : AnsiString; Const Source : AnsiS   
   ring;offs:cardinal) : Integer; overload;   
   Function RPos(c:char;const S : AnsiString):Integer; overload;   
   Function RPos (Const Substr : AnsiString; Const Source : AnsiString) :   
   Integer; overload;   
      
   function PosSet (const c:TSysCharSet;const s : ansistring ):Integer;   
   function PosSet (const c:string;const s : ansistring ):Integer;   
   function PosSetEx (const c:TSysCharSet;const s : ansistring;coun   
   :Integer):Integer;   
   function PosSetEx (const c:string;const s : ansistring;count:Integer):Integer;   
      
      
   but I think Wolf's suggestion to use tstringlist (with strictdelimiter and   
   delimiter =',') makes more sense.   
      
   var x : TStringList;   
      
   begin   
    x:=TStringList.Create;   
    x.delimiter:=','; x.strictdelimiter:=true;   
      
    while ...   
    begin   
    readln(f,sometext);   
    x.delimitedtext:=sometext;   
    // x[0] .. x[x.count-1] contains the fields here.   
    end;   
      
   This also works in Delphi (2006+)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|