having double quote when display value in edittext android

Issue

I’m getting String value from Webservice & try to display String value in Edittext using Android. I manage to display the value but i getting double quote, Example : “12.12”.Below is the code i done.Can anyone guide where is my mistake.Thanks in advance.

//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
result= convertStreamToString(stream);
    cText.setText(result);

public String convertStreamToString(InputStream is) 
 {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();

    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } 
    catch (IOException e) {
        e.printStackTrace();
    } 
    finally {
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return sb.toString();
}

Solution

I think its because you are getting the output from your webservice with double quotes. If the only problem you are facing is that the result string contains double quotes, then you can simply remove the double quotes by using the following code:

    String result = convertStreamToString(stream);
    result = result.replace("\"","\\\"");
    System.out.println(result);    //Result string without double quotes

Hope this helps.. Thanks..

Answered By – Shekhar Chikara

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published