Escaping double quotes in strings? lazarus / 61-Beginners ---------------------------------------------------------------------- py2pa · 2014-08-18 16:06 This code: Code: [Select]var   separators: TSysCharSet;   clue: PChar;   words: TStringList; begin   separators := [' '];   clue := '"Mary Poppins" is a musical film.';   extractstrings(separators,separators,clue,words); extracts the following five words from clue: Code: [Select]'"Mary Poppins"', 'is', 'a', 'musical', 'film' while what I want is to somehow escape (but not omit) the double quotes and get the following six words: Code: [Select]'"Mary', 'Poppins"', 'is', 'a', 'musical', 'film' Is this possible without writing a new function for the task? ---------------------------------------------------------------------- marcov · 2014-08-18 16:19 Maybe not with extractstrings, but you could try tstringlist, setting quotechar to something else. It then ignores quoting. Then you can check if each word starts or ends with a quote and complete it where necessary. ---------------------------------------------------------------------- py2pa · 2014-08-18 17:17 Quote from: marcov on August 18, 2014, 06:19:42 pmMaybe not with extractstrings, but you could try tstringlist, setting quotechar to something else. It then ignores quoting. Then you can check if each word starts or ends with a quote and complete it where necessary. Following your lead, I rewrote the part as: Code: [Select]words.strictdelimiter := True; words.delimiter := ' '; words.quotechar := '^'; words.delimitedtext := clue; and I just make sure the '^' doesn't show up in any clue. ---------------------------------------------------------------------- Dzandaa · 2022-11-09 15:37 Hi, Why don't you use Strings instead PChar? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TExperimentForm.BTestStringClick(Sender: TObject);var Str: String; SArr: TStringArray; i: integer;begin  Str := '"Mary Poppins" is a musical film.';  SArr := Str.Split([' ']);    for i := 0 to Length(SArr) -1 do Memo.Append(SArr[i]); end; B-> ---------------------------------------------------------------------- Thaddy · 2022-11-09 16:23 Nope:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}// make sure it is ansistringuses sysutils; // for the type helpersvar Str: String; SArr: TStringArray;begin  Str := '"Mary Poppins" is a musical film.';  SArr := Str.Split([' ','"'], TStringSplitOptions.ExcludeEmpty); // options are qualified  for str in SArr do writeln(str); // no need for explicit index," i" had to go ;)end. ---------------------------------------------------------------------- Dzandaa · 2022-11-09 18:26 Hi, You're right no need for index i (old c habit), but, Thaddy, I thing that py2pa want the " Quotewhile what I want is to somehow escape (but not omit) the double quotes and get the following six words: '"Mary', 'Poppins"', 'is', 'a', 'musical', 'film' B-> ---------------------------------------------------------------------- Thaddy · 2022-11-10 08:36 Just remove the second delimiter: '"' ---------------------------------------------------------------------- CM630 · 2022-11-28 13:04 Quote from: Thaddy on November 09, 2022, 05:23:21 pmNope:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...  for str in SArr do writeln(str); // no need for explicit index," i" had to goend.i seems fine to me, is not str a little too much? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  SArr: TStringArray;  i:integer;begin  memo.Clear;  SArr := '"Mary Poppins" is a musical film.'.Split([' ','"'], TStringSplitOptions.ExcludeEmpty);  for i := 0 to Length(SArr) -1 do Memo.Append(SArr[i]);end; ---------------------------------------------------------------------- Thaddy · 2022-11-28 13:19 Nope. this code is safer and smaller:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$mode objfpc}{$H+}uses sysutils;var  SArr: TStringArray;  s:string;begin  SArr := '"Mary Poppins" is a musical film.'.Split([' ','"'], TStringSplitOptions.ExcludeEmpty);  for s in Sarr do writeln(s);end.Same can be done with a memo.