ANDROID--How to take one part of html tag with fromHtml?

95 views Asked by At

I want to take one part of description from html tag. But I do not know how can I apply it?

Here is my Html tag:

İstanbul Çağlayan Adliyesi’nde teröristler tarafından silahla vurularak öldürülen savcı Mehmet Selim Kiraz’ın babası hastanede taziyeleri kabul ederken, yakınları da gözyaşı döktü. Savcı Kiraz’ın cenazesi Adli Tıp Kurumu morguna götürüldü.

I need to parse this part from description.

The following code give me all sentences in the description but I don't want some sentences which are in <a href=...></a> tags:

viewHolder.txtViewDescription.setText(Html.fromHtml(itemsData.get(position).getDescription()));

How can I apply it? Thanks for help...

3

There are 3 answers

0
Neerajlal K On BEST ANSWER

You can use this Regular expression to remove all anchor tags.

String your_string = "<a>your html content</a>useful text"
String exp = "<a href=.*</a>";
String result = your_string.replaceAll(exp, "");
1
Gabriella Angelova On

If I understand you well, you are trying to get the whole text, but without this from tags, so you could use a regex like this

str = str.replaceAll("<a href=([^<]*)>([^<]*)</a>", "");

and remove all tags. Then you could use the line you wrote to extract the text

viewHolder.txtViewDescription.setText(Html.fromHtml(itemsData.get(position).getDescription()));

Hopefully this helps you

0
Kartheek On

Try this regular expression for replacing all the hyperlink tags.

String regx = "<a [\\s]*href .*></a>";
String result = description.replaceAll(regx);