Java String.toUpperCase()
Just the other day I ran into a strange strange bug. I had a string of
characters that I had to build. And as a delimiter the host system I was
communicating with used char 254. Anyway I build out my string and sent it
to the host. On the host I was receiving char 222 as the delimiter! After
scratching my head and looking into it deeper it seemed odd that
hex : FE, binary: 11111110
was turning into
hex: DE, binary: 11011110
I tried the Locale.getDefault() and Locale.ENGLISH to no avail.
Could it be that the implementation of String.toUpperCase has a mask for
ALL chars except specific hard coded ones?
For now I'm using the following to get around the problem:
public static String toUpperCase(String input) {
char[] chars = input.toCharArray();
for(int i = 0; i < chars.length; ++i ) {
if( chars[i] > 96 && chars[i] < 123 ) {
chars[i] &= 223;
}
}
return new String(chars);
}
my question is am I missing something? Is there a better way that I am not
aware of? Thanks a bunch!
No comments:
Post a Comment