if I replace ' with \' in a delphi str and then execute in JS, it will run wrong because delphi will replace ' with ''.
see:
delphi str:
R de cop a k'a d complex
GetTxtJavaStr := 'TitleFRef = ' + DealJsSpeChar(TitleFRef) +';'
Chromium1.Browser.MainFrame.ExecuteJavaScript(GetTxtJavaStr , 'about:blank', 0 );
function DealJsSpeChar(Astrforjs: string): string;
var JsSpeCharList: TstringList;
i:integer;
begin
result := '';
JsSpeCharList:= TStringList.Create;
//['\', CHAR(39), '"', '&', '\\'] ; +','+ [ '\' +','+ CHAR(39) +','+ '"' +','+ '&' +','+ '\\' ]
//JsSpeCharList.Delimiter:=','; // CHAR(39):'; CHAR(34) "; CHAR(38) &; CHAR(92) \;
//JsSpeCharList.DelimitedText := CHAR(34) +','+ CHAR(38) +','+ CHAR(39) +','+ CHAR(92) ;
for i := 0 to 100 do
begin
if i in [34, 38, 39, 92] then JsSpeCharList.Add(CHAR(i));
end;
for i := 0 to JsSpeCharList.Count-1 do
begin
if AnsiPos(JsSpeCharList.Strings,Astrforjs )>0 then
result := StringReplace(Astrforjs, JsSpeCharList.Strings, '\'+ JsSpeCharList.Strings,[rfReplaceAll])
end;
result := QuotedStr(result);
FreeAndNil(JsSpeCharList);
end;
Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
deal with quoted str
Re: deal with quoted str
result := char(39) + result + char(39); should be ok!