Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Replace <br\ /> tag

Tags:

java

android

We are developing a app. In which we getting a data from a json array . In that i want to replace a tag.But the emulator throws an error .Like Invalid Syntax . my code:

top=top.replaceall("<br\/>"," ");

Please help. Thanks In Advance

like image 402
Deepu Avatar asked Dec 12 '22 20:12

Deepu


2 Answers

use

top=top.replaceall("<br\\/>"," ");

instead of

top=top.replaceall("<br\/>"," ");

EDIT : maybe String.relpaceall not work. so best way is use Regular Expressions's Matcher as :

Pattern p = Pattern.compile("<br\\/>");
String tempstr = "I love <br/>  <br/>  <br/> <br/>.";

Matcher matcher = p.matcher(tempstr );
String tmp = matcher.replaceAll("Android");
System.out.println(tmp);

OUTPUT IS:

"I love Android. Android Android Android."

like image 141
ρяσѕρєя K Avatar answered Dec 27 '22 22:12

ρяσѕρєя K


Try this.

String res = Html.fromHtml(yourString).toString();
like image 42
nithinreddy Avatar answered Dec 27 '22 20:12

nithinreddy