Search code examples
javaandroidgoogle-geocoder

How to replace special charcters like "ö" from a string and give them the right characters "Ö"?


Hey I use the reverse Google Geocoder and when the cityname is for example "Königsaich" then the geocoder names it "Königsaich" . How do I filter the "ö" character and replace it with the right character "ö" ?

EDIT:

My code:

public JSONObject getJSONCity(double lat, double lon){

         HttpGet httpGet = new HttpGet("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lon+"&sensor=false");
            HttpClient client = new DefaultHttpClient();
            HttpResponse response;
            StringBuilder stringBuilder = new StringBuilder();

            try {
                response = client.execute(httpGet);
                HttpEntity entity = response.getEntity();
                InputStream stream = entity.getContent();
                int b;
                while ((b = stream.read()) != -1) {
                    stringBuilder.append((char) b);
                }
            } catch (ClientProtocolException e) {
                } catch (IOException e) {
            }

            JSONObject jsonObject = new JSONObject();
            try {
                jsonObject = new JSONObject(stringBuilder.toString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return jsonObject;
    }


    public String getCityname(double lat, double lon){

        JSONObject ret = getJSONCity(lat,lon); 
         JSONArray jsonArray;

         JSONObject location;
         String location_string;

         try {
             jsonArray = ret.getJSONArray("results").getJSONObject(0).getJSONArray("address_components");
             cityname = jsonArray.getJSONObject(2).getString("long_name");

             //Get JSON Array called "results" and then get the 0th complete object as JSON        
             location = ret.getJSONArray("results").getJSONObject(0); 
             // Get the value of the attribute whose name is "formatted_string"
             location_string = location.getString("formatted_address");

             System.out.println(" results: " + location_string);

             System.out.println(" My City: " + cityname);
         } catch (JSONException e1) {
             e1.printStackTrace();
         }
         return cityname;
    }

Can anyone give me an example?


Solution

  • String actualstring ="what ever your string which you want to replace here get ";
             if(actualstring.contains("here your string which u want to chk"));
                    { 
                       // it chk weather it contain that string which u want to replace 
               actualstring.replace("target", "replacement");
                     }