如何在字符串java中替换

时间:2015-01-07 08:07:10

标签: java android regex xml

当我从网上下载xml时,会附加到我的xml。

如何从字符串中替换它。我知道我可以用

来做

子串。但是有一个正则表达式来做这个..

正在运行代码

XmlParser parser = new XmlParser();

xml = parser.getXmlFromUrl(params[0]);

xml = xml.substring(3);

XmLParse方法

public String getXmlFromUrl(String url) 
    {       
        String xml = null;
        try 
        {
            //default http client
            HttpClient httpClient = new DefaultHttpClient();

            HttpPost httpPost = new HttpPost(url);

            System.out.println("URL IN PARSER:==="+url+"====");

            HttpResponse httpResponse = httpClient.execute(httpPost);

            HttpEntity httpentity = httpResponse.getEntity();

            xml = EntityUtils.toString(httpentity);   

            Log.d("response", xml);
        } 
        catch(UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } 
        catch (ClientProtocolException e) 
        {
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            e.printStackTrace();
        }


        return xml;
    }

1 个答案:

答案 0 :(得分:-1)

是utf-8中的BOM。试试这个:

xml = EntityUtils.toString(entity, "utf-8");