EGHDK EGHDK - 5 months ago 12
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;
try{


HttpClient client = new DefaultHttpClient();
URI website = new URI("http://example.com/getInbox.php?where="+where);

HttpPost post_request = new HttpPost();
post_request.setURI(website);


HttpGet request = new HttpGet();

request.setURI(website);
//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) {
sb.append(l+nl);

}
in.close();
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
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):