Java – how to handle tags in Android
•
Java
I've been looking for some time and haven't been able to find the right answer for this one To make a long story short, I'm searching a web page for my inbox I desperately 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 tags as plain text Try to read them as "next line / new line" Any ideas?
My method code:
public String getIn@R_521_2419@(String where){
BufferedReader in = null;
String data = null;
try{
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://example.com/getIn@R_521_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
Solution
String lineSep = System.getProperty("line.separator");
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
二维码
