i'm working on gwt 2.6.1 project receiving data mysql database.
all working fine have problem öäüÖÄÜß (special chars) german language.
public void onsuccess(rpcobjectstringarray result) { string[] resultarray = result.getstringarray(); arrays.sort(resultarray,new comparenocaseumlaut()); (int = 0; < resultarray.length; i++) { system.out.println(result[i]); } } public class comparenocaseumlaut implements comparator<string> { @override public int compare(string arg0, string arg1) { collator collator = collator.getinstance(locale.german); collator.setstrength(collator.secondary); // non case sensitive return collator.compare(arg0,arg1); } }
but can't work while gwt doesen't support collator lib.
so - tried (to make easy follow - i've changed resultarray example):
string[] resultarray = { "abc", "öbc", "bbc", "the", "abd", "x"}; public class comparenocaseumlaut implements comparator<string> { @override public int compare(string arg0, string arg1) { string string0 = arg0.tolowercase(); string string1 = arg1.tolowercase(); string0.replace("ä", "a"); string0.replace("ö", "o"); string0.replace("ü", "u"); string0.replace("ß", "s"); string1.replace("ä", "a"); string1.replace("ö", "o"); string1.replace("ü", "u"); string1.replace("ß", "s"); return string0.compareto(string1); }
the result: "abc" "abd" "bbc" "the" "x" "öbc"
i've debugged .replace function doesen't act expected. can't replace "ö" char - cause couldn't find it. compare "==" same...
i've changed charset in eclipse project utf-8 - nothing changed.
i'm new java (for couple of months , gwt oldie in programming), please give me details - or link... study myself , bring result here. @ moment don't know have begin....
i read plugins eclipse , gwt internationalization sounds high understand. otherwise learn - helpfully?
thx in advance!
ok - i've tested again marvins hint - it's working :) silly fault...
before changed project utf-8, tried correct way. since changed utf-8 charset doesn't tried again, ran faulty code because want demonstrate fault nothing :)
i've changed it...
public class comparenocaseumlaut implements comparator<string> { @override public int compare(string arg0, string arg1) { string string0 = arg0.tolowercase(); string string1 = arg1.tolowercase(); string0 = string0.replace("ä", "a"); string0 = string0.replace("ö", "o"); string0 = string0.replace("ü", "u"); string0 = string0.replace("ß", "s"); string1 = string1.replace("ä", "a"); string1 = string1.replace("ö", "o"); string1 = string1.replace("ü", "u"); string1 = string1.replace("ß", "s"); return string0.compareto(string1); } }
something creepy case sensitive in result array ... it's late figure out now...