On 23/12/16 08:14, Bo Berglund wrote:
Is there a quick way to split a string of whitespace separated values
into the separate members?
It is possible that a custom string parser (something along these lines) might improve your processing speed:

type
    TDoubleArray = array of Double;

function StrToDblArray(const aString: string): TDoubleArray;
var
  c: Char;
  prevNumeric: boolean = False;
  sNum: string = '';
  number: double;

  function IsNumeric: boolean; inline;
  begin
    Exit(c in ['.', '0'..'9']);
  end;

begin
  SetLength(Result, 0);
  for c in aString do begin
    case IsNumeric of
      False: if prevNumeric then begin
                if TryStrToFloat(sNum, number) then begin
                  SetLength(Result, Length(Result) + 1);
                  Result[High(Result)]:=number;
                end;
                sNum:='';
                prevNumeric:=False;
             end;
      True: begin
              sNum:=sNum + c;
              if not prevNumeric then
                prevNumeric:=True;
            end;
    end;
  end;
  if prevNumeric and TryStrToFloat(sNum, number) then begin
    SetLength(Result, Length(Result) + 1);
    Result[High(Result)]:=number;
  end;
end;
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to