1

I have a response in html form from the server, now I want to read the characters or say data of between particular tag, for example: font tag starting---(The data that I want to read)----font tag ending.

I have stored the string in a String Variable named "response".

How can I do this in android?

Thanks, david

2 Answers 2

4

You can probably use regex Pattern. Here's a little example, though it can be probably made more efficient and abstract:

public static void main(final String[] args) { final String html = "Some text <font> here </font>, and some <font>there</font>"; final Pattern ptrn = Pattern.compile("<font>(.+?)</font>"); final Matcher mtchr = ptrn.matcher(html); while (mtchr.find()) { final String result = html.substring(mtchr.start(), mtchr.end()).replace("<font>", "").replace("</font>", ""); System.out.println(result); } } 

Result:

 here there 

P.S. You probably shouldn't use this for large responses (and I think it's not adviced to use regex for html). Maybe you should use some parser (SAX for one).

Sign up to request clarification or add additional context in comments.

Comments

0

are you in a browser ? if so you can use jQuery or simply :

document.getElementById('divID').innerHTML; 

1 Comment

I have stored the string in a String Variable named "response".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.