fork(8) download
  1. var
  2. p : PChar = '[123, 2345, ''test'', ''str1, str2'', -1234, ''str3 ''is'' str4'']';
  3. Chunks : Integer = 1; BetweenQuotes : Boolean = false;
  4.  
  5. begin Writeln(p);
  6. while p^ <> #0 do begin inc(p);
  7. case p^ of
  8. '''': BetweenQuotes := not BetweenQuotes;
  9. ',': if not BetweenQuotes then inc(Chunks)
  10. end
  11. end;
  12. Writeln('Chunks = ', Chunks); Readln
  13. end.
Success #stdin #stdout 0s 232KB
stdin
Standard input is empty
stdout
[123, 2345, 'test', 'str1, str2', -1234, 'str3 'is' str4']
Chunks = 6