如何用JavaScript从字符串中删除`//&lt !! [CDATA [`and end`//]]>`? [英] How to remove `//<![CDATA[` and end `//]]>` with javascript from string?

查看:148
本文介绍了如何用JavaScript从字符串中删除`//&lt !! [CDATA [`and end`//]]>`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从字符串中删除//<![CDATA[并以javascript结尾//]]>?

How to remove //<![CDATA[ and end //]]> with javascript from string?

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方法,例如:

You can use the String.prototype.replace method, like:

title = title.replace("<![CDATA[", "").replace("]]>", "");

这将用任何内容替换每个目标子字符串.请注意,这只会替换每个匹配项的第一个匹配项,并且如果您要删除所有匹配项,则需要使用正则表达式.

This will replace each target substring with nothing. Note that this will only replace the first occurrence of each, and would require a regular expression if you want to remove all matches.

参考:

这篇关于如何用JavaScript从字符串中删除`//&lt !! [CDATA [`and end`//]]&gt;`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆