问题
I have a string which has html tags. I want to remove the html tags completely. How can I achieve this? The string goes something like this
<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>
回答1:
I use this function this way,
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;
}
I tried to do that with the function replaceAll()
using regular experssion, but never had a good way.
来源:https://stackoverflow.com/questions/9647578/removing-html-tags-in-from-a-string-in-android