如何在字符串
中同时处理撇号和引号转换目前我只处理撇号
var strname = data[i].name
strname = strname.replace("'","@");
以及如何在以后更换它 strrename = strrename.replace(“@”,“'”);
答案 0 :(得分:1)
我不确定你想在这里做什么,但如果你试图用@符号替换单引号和双引号,那么这应该有效:
var strname = data[i].name.replace("'","@").replace("\"","@");
答案 1 :(得分:1)
做两次替换是昂贵且不必要的......
strname = strname.replace(/["']/g, "@");
阅读https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions和https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/replace。
答案 2 :(得分:0)
就像你处理撇号一样。
strname.
replace('"', 'what_you_want_quotes_to_be_replaced_with').
replace("'", 'what_you_want_apostrophes_to_be_replaced_with');
答案 3 :(得分:0)
strname = strname.replace("'","@");
strname = strname.replace("\"","@");