Java – how to handle tags in Android
•
Android
I've been looking for a while and haven't been able to find the right answer for this one. To make a long story short, I'm searching from a web page to use as my inbox. I urgently need to skip the lines between each "message", so I put the tag in my PHP. It works perfectly in a web browser, but in my Android application, I can actually think of labels as plain text. Try reading them as "next line / new line". Any ideas?
My method code:
public String getIn@R_860_2419@(String where){
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://example.com/getIn@R_860_2419@.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";
}
}
Output in web pages:
eg test
eg test
eg lol
eg lol
eg testing
Output in Android:
eg test<br />eg test<br />eg lol<br />eg lol<br />eg testing<br />eg
resolvent:
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):
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码