I have the following problem. I am trying to replace german umlauts like ä, ö, ü in java. But it simply does not work. Her
ENCODING ENCODING ENCODING....
Different source of input may result in complications in the String encoding. for example one may have UTF-8
encoding while the other one is ISO
some people suggested that the code works for them, therefore, its most likely that your Strings have different encoding while processed. (different encoding results in different byte array thus no replacing...)
to solve your problem from its root,you must make sure, each of your sources uses exactly same encoding.
try this exercise and it hopefully helps you to solve your problem:
1-try this:
System.out.println(Arrays.asList("Ä".getBytes()); //1 and 2 should have same results
System.out.println(Arrays.asList(new String("Ä","UTF-8").getBytes()); //1 and 2 should have same results
System.out.println(Arrays.asList(new String("Ä","UTF-32").getBytes()); //should have a different results from one and two
System.out.println(Arrays.asList(orig.getBytes()); //look for representation and search for pattenr of numbers (this bit is the hard bit I guess).
System.out.println(Arrays.asList(new String(orig,"UTF-32").getBytes()); //look for representation and search for pattenr of numbers (this bit is the hard bit I guess).
the next step is to see how the orgi
string is formed. for example if you have received from web, make sure your POST and GET method are using your preferred encoding
EDIT 1:
try this:
{ { new String("Ä".getBytes(),"UTF-8"), "Ae" }, ... };
if this one didn't work try this:
byte[] bytes = {-61,-124}; //byte representation of Ä in utf-8
String Ae = new String(bytes,"UTF-8");
{ { Ae, "Ae" }, ... }; //and do for the rest