4 回答
TA贡献2039条经验 获得超8个赞
str = str.replace(/[“”]/g, '"');str = str.replace(/[‘’]/g, "'");
str = str.replace(/[“”]/g, '"').replace(/[‘’]/g,"'");
replace
返回一个新字符串,该字符串中有一些或全部匹配的模式被替换。 …
此方法不更改调用的字符串对象。它只是返回一个新字符串。
TA贡献1775条经验 获得超11个赞
var s = "“This is a test” ‘Another test’";s = s.replace(/[“”]/g, '"').replace(/[‘’]/g,"'");document.writeln(s);
"This is a test" "Another test"
var s = "“This is a test” ‘Another test’";for (var i = 0; i < s.length; i++) {
document.writeln(s.charAt(i) + '=' + s.charCodeAt(i));}? = 63.
“ = 8220, ” = 8221, ‘ = 8216’ = 8217charCodeAt()replace()
TA贡献1812条经验 获得超5个赞
使用CharCode调用ASCII字符,这将消除不同浏览器和操作系统之间的错误空间。这也有助于双语使用(口音等)。
将智能引号替换为单引号
function unSmartQuotify(n){
var name = n;
var apos = String.fromCharCode(39);
while (n.indexOf("'") > -1)
name = name.replace("'" , apos);
return name;}添加回答
举报
