从Android的字符串删除HTML标签 [英] Removing html tags in from a string in android

查看:368
本文介绍了从Android的字符串删除HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有HTML标签的字符串。我想彻底删除HTML标签。我怎样才能做到这一点?
该字符串是这样的

 <&messageContent的GT;< P>< A HREF =htt​​p://www.business-standard.com/india/news/markets-trade-flatpositive-bias/ 159747 /的TARGET =_空白><强>市场交易平淡正偏压< / STRONG>< / A>< BR />
<一href=\"http://www.moneycontrol.com/news/local-markets/nifty-choppy-icici-bank-infosys-wipro-gain_677519.html\"目标=_空白><强>俏皮震荡; ICICI银行,Infosys公司,Wipro的增益< / STRONG>< / A>< BR />
BSE 17127.09(-46.20)LT; BR />
NSE 5208.15(-14.25)所述; / P>
< /&messageContent的GT;


解决方案

我用这个函数这种方式,

 公共字符串removeTags(字符串中)
    {
        INT索引= 0;
        INT索引2 = 0;
        而(索引!= - 1)
        {
            指数= in.indexOf(&下;);
            索引2 = in.indexOf(>中,指数);
            如果(指数= - 1安培;!&安培;!索引2 = - 1)
            {
                在= in.substring(0,索引).concat(in.substring(索引2 + 1,in.length()));
            }
        }
        返回;
    }

我想这样做与功能的replaceAll()使用正则表达研究,但从来没有一个好办法。

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>

解决方案

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.

这篇关于从Android的字符串删除HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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