Removing html tags in from a string in android [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-14 00:13:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!