Reputation: 4823
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
Upvotes: 1
Views: 1501
Reputation: 18107
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).
Upvotes: 4
Reputation: 11541
are you in a browser ? if so you can use jQuery or simply :
document.getElementById('divID').innerHTML;
Upvotes: 0