Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TIntegerArray = array of Integer;
- procedure ExtractIntegers(const Strings: TArrayOfString; out Integers: TIntegerArray);
- var
- S: string;
- I: Integer;
- Value: Integer;
- begin
- for I := 0 to GetArrayLength(Strings) - 1 do
- begin
- // trim the string copied from a substring after the ":" char
- S := Trim(Copy(Strings[I], Pos(':', Strings[I]) + 1, MaxInt));
- // try to convert the value from the previous step to integer;
- // if such conversion fails, because the string is not a valid
- // integer, it returns -1 which is treated as unexpected value
- // in the input file
- Value := StrToIntDef(S, -1);
- // so, if a converted value is different from unexpected value,
- // add the value to the output array
- if Value <> -1 then
- begin
- SetArrayLength(Integers, GetArrayLength(Integers) + 1);
- Integers[GetArrayLength(Integers) - 1] := Value;
- end;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement