【问题标题】:Removing html tags in from a string in android [closed]从android中的字符串中删除html标签[关闭]
【发布时间】:2012-03-10 15:24:31
【问题描述】:

我有一个带有 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>

【问题讨论】:

  • 第 1 步:研究这个问题是否已经得到解答。 ;)
  • 尚无太多研究
  • 您应该在此处提问之前这样做,并将结果包含在您的问题中,以防您无法自行解决。我现在投票结束这个问题,因为我在一分钟内找到了答案,我想你也会打到它。 :)
  • Pattern tags = Pattern.compile ("&lt;/?[^&gt;]+&gt;"); Matcher match = tags.matcher (yourContent); // here you specify the string you want to modify (HTML) String result = match.replaceAll("");
  • @Dinesh:他什么都没做,你仍然可以编辑你的问题。

标签: android html string tags


【解决方案1】:

我就是这样使用这个功能的,

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;
    }

我尝试通过函数replaceAll() 使用正则表达式来做到这一点,但从来没有一个好的方法。

【讨论】:

    猜你喜欢
    • 2011-06-20
    • 1970-01-01
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2019-01-06
    • 1970-01-01
    相关资源
    最近更新 更多