EGHDK EGHDK - 1 year ago 68
Java Question

How to handle <br /> tags in Android

I've been searching for a while now onine and just havn't been able to nail the correct answer for this one. Long story short, I'm retreiving a webpage from onine to use as my inbox. I desperately need to skip lines in between each "message" so I put
tags in my php. It works perfectly in a web broweser but, in my Android application, I can actually see the
tags as plain text. Just trying to read them as "next/new lines". Any ideas?

My method code:

public String getInbox(String where){

BufferedReader in = null;
String data = null;

HttpClient client = new DefaultHttpClient();
URI website = new URI(""+where);

HttpPost post_request = new HttpPost();

HttpGet request = new HttpGet();

//executing actual request

//add your implementation here
HttpResponse response = client.execute(request);

in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) != null) {

data = sb.toString();

return data;
}catch (Exception e){
return "ERROR";



The output in a webpage:

eg test
eg test
eg lol
eg lol
eg testing

The output in android:

eg test<br />eg test<br />eg lol<br />eg lol<br />eg testing<br />eg

Answer Source
String lineSep = System.getProperty("line.separator");
String yourString= "test<br />eg test<br />eg lol<br />eg lol<br />eg testing<br />eg34 ernestggggg";

yourString= yourString.replaceAll("<br />", lineSep):