我有一个包含html标签的字符串。我想完全删除html标签。我怎样才能做到这一点? 字符串就是这样的
<messageContent><p><a href="http://www.business-standard.com/india/news/markets-trade-flatpositive-bias/159747/on" target="_blank"><strong>Markets trade flat with positive bias</strong></a><br />
<a href="http://www.moneycontrol.com/news/local-markets/nifty-choppy-icici-bank-infosys-wipro-gain_677519.html" target="_blank"><strong>Nifty choppy; ICICI Bank, Infosys, Wipro gain</strong></a><br />
BSE 17127.09 (-46.20)<br />
NSE 5208.15 (-14.25)</p>
</messageContent>
答案 0 :(得分:2)
我以这种方式使用这个功能,
public String removeTags(String in)
{
int index=0;
int index2=0;
while(index!=-1)
{
index = in.indexOf("<");
index2 = in.indexOf(">", index);
if(index!=-1 && index2!=-1)
{
in = in.substring(0, index).concat(in.substring(index2+1, in.length()));
}
}
return in;
}
我尝试使用常规experssion的函数replaceAll()
来做这件事,但从来没有一个好方法。