aditi
aditi

Reputation: 39

How to remove unwanted characters in a string

hi I am getting a json response from the server. I parsed it . but the String from the response looked like this

roominfo<br /><br /> <p><strong>Notifications and Fees:</strong><br /></p><p><ul><li>A resort fee is included in the total price displayed</li> </ul></p><p></p><p></p> <p>The following fees and deposits are charged by the property at time of service, check-in, or check-out. <ul><li>Valet parking fee: USD 30 per night (in/out privileges)</li><li>Pet fee: USD 45 per stay</li><li>Fee for wireless Internet in all public areas: USD 11.95 (for 24 hours, rates may vary)</li><li>Fee for in-room wireless Internet: USD 11.95 (for 24 hours, rates may vary)</li> </ul></p><p>The above list may not be comprehensive. Fees and deposits may not include tax and are subject to change. </p>

how to remove the unwanted characters from this string

Upvotes: 0

Views: 2054

Answers (3)

Nurlan
Nurlan

Reputation: 673

Use jsoup parse

jsoup

for example you can do like this in java using jsoup:

String html = "<p>An <a href='http://example.com/'><b>example</b></a> link.</p>";
Document doc = Jsoup.parse(html);
Element link = doc.select("a").first();

String text = doc.body().text(); // "An example link"
String linkHref = link.attr("href"); // "http://example.com/"
String linkText = link.text(); // "example""

String linkOuterH = link.outerHtml(); 
// "<a href="http://example.com"><b>example</b></a>"
String linkInnerH = link.html(); // "<b>example</b>"

Upvotes: 0

there are some html tags which are supported by Html Class . see this http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html

you can android Html class to remove or handle these tags. format would be like this.

Html.fromHtml(text).toString();

however there are several html tags which are not supported by html class so you can use webview to handle those tags.

Upvotes: 0

If your unwanted character are HTML tags then use this

 String noHTMLString = htmlString.replaceAll("\\<.*?>","");

It uses a regular expression to remove any text that is enclosed with brackets.

Upvotes: 2

Related Questions