How to extract all the substrings between single quotation marks in Pascal

1 Answer

0 votes
program ExtractQuotedStrings;

uses
  SysUtils, StrUtils;

var
  S: string;
  StartPos, EndPos: Integer;
begin
  S := 'I like ''Pascal'', ''C'', ''C#'' ''Java'' and ''Python''.';

  StartPos := 1;

  while True do
  begin
    StartPos := PosEx('''', S, StartPos);
    if StartPos = 0 then Break;

    EndPos := PosEx('''', S, StartPos + 1);
    if EndPos = 0 then Break;

    Writeln(Copy(S, StartPos + 1, EndPos - StartPos - 1));

    StartPos := EndPos + 1;
  end;
end.



{
run:

Pascal
C
C#
Java
Python
  
}

 



answered Oct 11 by avibootz

Related questions

1 answer 191 views
...