Eliminando etiquetas html de una cadena en android [cerrado]

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>

preguntado el 10 de marzo de 12 a las 15:03

Step 1: Research if this question is already answered. ;) -

nothing much still researching -

You should do that before you ask here and include the result into your question in case you can't solve it on your own. I vote to close this question now since I found the answer within one minute, I guess you will hit it too. :) -

Pattern tags = Pattern.compile ("</?[^>]+>"); Matcher match = tags.matcher (yourContent); // here you specify the string you want to modify (HTML) String result = match.replaceAll(""); -

@Dinesh: He didn't do anything, you can still edit your question. -

1 Respuestas

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.

respondido 10 mar '12, 18:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.