I have come across a strange issue. In the below piece of code, I am searching for the presence of ß.
public static void main(String[] args) {
char [] chArray = {'ß'};
String str = "Testß";
for(int i=0; i<chArray.length; i++){
if(str.indexOf(chArray[i])>-1){
System.out.println("ß is present");
break;
}
}
}
I have a web application running on JBOSS in linux, Java 6. The above code doesn't detect the presence of ß when include the code in the above specified application. Surprisingly, if I compile the same file in my eclipse workspace and then apply the patch in the application it runs as expected!
Points to note:
I changed the value from ß to unicode equivalent to \u00DF in the array declaration, but still the behavior is same.
char [] chArray = {'\u00DF'};
When I decompiled the class file generated the character array declared value was shown as 65533, which is \uFFFD, nothing but replacement character which is used for unidentified symbol. I used JD-GUI as decompiler, which I dont see trustworthy!
Need your help folks! I am sure it is not same as: case sensitive issue of beta Java's equalsIgnoreCase fails with ß ("Sharp S" used in German alphabet)
Thanks in advance
I think your problem is the encoding of ß. You have two options to solve your error:
First convert your java source code into ascii chars, and then compile it:
native2ascii "your_class_file.java"
javac "your_class_file.java"
Compile your java file with your encoding, utf-8
on linux and iso-8859-15
on windows:
javac -encoding "encoding" "your_class_file.java"
As far as I can judge it, it should have worked with replacing "ß"
with "\u00df"
. If the solutions above don't work, print every char and its unicode value to System.out
and look which char is 'ß'.
Another error might be that you read the text in an encoding that doesn't support ß; try reading your String by reading the bytes and call:
String input = new String(input_bytes, StandartCharsets.UTF_8); // on linux
String input = new String(input_bytes, StandartCharsets.ISO_8859_1); // on windows
For more information on charsets, see StandartCharsets class reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With