Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,848 questions

51,769 answers

573 users

How to split a string with multiple separators in Pascal

1 Answer

0 votes
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
  
*)

 



answered Jul 21, 2025 by avibootz
...