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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,239 questions

56,142 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
...