加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何处理Android中的标签

发布时间:2020-12-15 05:08:22 所属栏目:Java 来源:网络整理
导读:我一直在寻找一段时间,并且没有能够为这一个找到正确的答案.长话短说,我正在从一个网页上搜索用作我的收件箱.我迫切需要跳过每个“消息”之间的行,所以我把标签放在我的 PHP中.它在web浏览器中完美运行,但在我的 Android应用程序中,我实际上可以将标签视为纯
我一直在寻找一段时间,并且没有能够为这一个找到正确的答案.长话短说,我正在从一个网页上搜索用作我的收件箱.我迫切需要跳过每个“消息”之间的行,所以我把标签放在我的 PHP中.它在web浏览器中完美运行,但在我的 Android应用程序中,我实际上可以将标签视为纯文本.试着将它们读作“下一行/新行”.有任何想法吗?

我的方法代码:

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";

        }

        }

网页中的输出:

eg test
eg test
eg lol
eg lol
eg testing

android中的输出:

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

解决方法

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):

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读