Forum > Beginners
Escaping double quotes in strings?
py2pa:
This code:
--- Code: ---var
separators: TSysCharSet;
clue: PChar;
words: TStringList;
begin
separators := [' '];
clue := '"Mary Poppins" is a musical film.';
extractstrings(separators,separators,clue,words);
--- End code ---
extracts the following five words from clue:
--- Code: ---'"Mary Poppins"', 'is', 'a', 'musical', 'film'
--- End code ---
while what I want is to somehow escape (but not omit) the double quotes and get the following six words:
--- Code: ---'"Mary', 'Poppins"', 'is', 'a', 'musical', 'film'
--- End code ---
Is this possible without writing a new function for the task?
marcov:
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:
--- Quote from: marcov on August 18, 2014, 06:19:42 pm ---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.
--- End quote ---
Following your lead, I rewrote the part as:
--- Code: ---words.strictdelimiter := True;
words.delimiter := ' ';
words.quotechar := '^';
words.delimitedtext := clue;
--- End code ---
and I just make sure the '^' doesn't show up in any clue.
Dzandaa:
Hi,
Why don't you use Strings instead PChar?
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Nope:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$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.
Navigation
[0] Message Index
[#] Next page