【问题标题】:remove HTML commands from string titanium从字符串 Titan 中删除 HTML 命令
【发布时间】:2016-04-01 11:37:10
【问题描述】:
我有这样的字符串:
<div> This is a test </div>
如何删除<div> 和</div> 或其他命令?
我有这个用于总和字符:
var FinalSTR = mySTR.replace(/<(?:.|)*?>/gm, '');
但对于文本中带有<>或</>的命令不起作用
【问题讨论】:
标签:
android
ios
iphone
titanium
titanium-mobile
【解决方案1】:
你可以用这个命令替换所有的标签:
var FinalSTR = mySTR.replace( /<[^>]+>/g, '' );
[^>]匹配非>的字符
[^>]+匹配非>的所有连续字符
`]+>̀ 匹配任意标签
【解决方案2】:
尝试关注它可能对你有用。
public String textFromHtml(String htmls) {
return Html.fromHtml(htmls).toString();
}