-1

I'm trying to capitalize and normalize unicode characters on a String, but none of the methods work as expected. Here is the related code:

String in = input.getText().toString();
            in.toUpperCase();
            System.out.println(in);
            in= Normalizer.normalize(in,Normalizer.Form.NFC);
            System.out.println(in);
            stripOut.setText(in);

First the "toUpperCase()" method doesn't do nothing. Second the "Normalize" method doesn't remove the accents but move them to the next character. Input-Output examples:

Input: φάε ήλιο δεν ξέρεις
UpperCase.out﹕ φάε ήλιο δεν ξέρεις
Normalize.out φάε ήλιο δεν ξέρεις

Input: Βέλγιο φορά δρόμους γιατί
UpperCase.out: Βέλγιο φορά δρόμους γιατί
Normalize.out: Βέλγιο φορά δρόμους γιατί

Any ideas?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724

2 Answers2

1

First the "toUpperCase()" method doesn't do nothing.

Java Strings are immutable and you are not capturing the new uppercase string returned by the method.

Second the "Normalize" method doesn't remove the accents but move them to the next character.

Normalization does not remove accents. It just just ensures unicode characters are represented in a consistent way.

To remove accents, normalize to the decomposed NFD form and remove non-letter characters. See Is there a way to get rid of accents and convert a whole string to regular letters?

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303
0

String is immutable in java. You cannot change it " in" value by calling

"in.toUpperCase();"

If you want to do that, you can do by

 in= in.toUpperCase();
Anil Kumar
  • 2,521
  • 7
  • 23
  • 40