如何删除//<![CDATA [和结束//]]>用JavaScript从字符串?
var title = "<![CDATA[A Survey of Applications of Identity-Based Cryptography in Mobile Ad-Hoc Networks]]>" ;
需要成为
var title = "A Survey of Applications of Identity-Based Cryptography in Mobile Ad-Hoc Networks";
怎么做?
解决方法:
您可以使用String.prototype.replace方法,例如:
title = title.replace("<![CDATA[", "").replace("]]>", "");
这将替换任何目标子字符串.请注意,这只会替换每个匹配项的第一个匹配项,如果要删除所有匹配项,则需要使用正则表达式.
参考:
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace