program SplitExample;
const
MAX_TOKENS = 64;
TOKEN_LEN = 32;
DELIMITERS = ',;|-_';
type
TTokenArray = array[0..MAX_TOKENS - 1] of string;
procedure SplitByDelimiters(const input: string; const delimiters: string; var tokens: TTokenArray; var count: Integer);
var
temp: string;
token: string;
i: Integer;
begin
temp := input;
count := 0;
i := 1;
token := '';
while i <= Length(temp) do
begin
if Pos(temp[i], delimiters) > 0 then
begin
if token <> '' then
begin
tokens[count] := token;
Inc(count);
token := '';
end;
end
else
token := token + temp[i];
Inc(i);
end;
if token <> '' then
begin
tokens[count] := token;
Inc(count);
end;
end;
var
input: string;
tokens: TTokenArray;
tokenCount, i: Integer;
begin
input := 'abc,defg;hijk|lmnop-qrst_uvwxyz';
SplitByDelimiters(input, DELIMITERS, tokens, tokenCount);
for i := 0 to tokenCount - 1 do
WriteLn(tokens[i]);
end.
(*
run:
abc
defg
hijk
lmnop
qrst
uvwxyz
*)