Advertisement
TLama

Untitled

Mar 3rd, 2014
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.92 KB | None | 0 0
  1. type
  2.   TIntegerArray = array of Integer;
  3.  
  4. procedure ExtractIntegers(const Strings: TArrayOfString; out Integers: TIntegerArray);
  5. var
  6.   S: string;
  7.   I: Integer;
  8.   Value: Integer;
  9. begin
  10.   for I := 0 to GetArrayLength(Strings) - 1 do
  11.   begin
  12.     // trim the string copied from a substring after the ":" char
  13.     S := Trim(Copy(Strings[I], Pos(':', Strings[I]) + 1, MaxInt));
  14.     // try to convert the value from the previous step to integer;
  15.     // if such conversion fails, because the string is not a valid
  16.     // integer, it returns -1 which is treated as unexpected value
  17.     // in the input file
  18.     Value := StrToIntDef(S, -1);
  19.     // so, if a converted value is different from unexpected value,
  20.     // add the value to the output array
  21.     if Value <> -1 then
  22.     begin
  23.       SetArrayLength(Integers, GetArrayLength(Integers) + 1);
  24.       Integers[GetArrayLength(Integers) - 1] := Value;
  25.     end;
  26.   end;
  27. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement