I am trying to combine alphabetical characters with accents in java. For example: Combining the letter "e" (\u0065) with a combing grave accent (\u0300). I have attempted numerous ways in java and believe I should use java.text.Normalizer but cannot figure out how to do it.
I have attempted the following:
String combinedLetter = Normalizer.normalize("\u0065\u0300", Form.NFKD);
And
Char CombinedLetter = (char) (0+0065 + 0+0300));
But neither have worked thus far, any ideas on how to do this? I cannot just use the character for é as I need to do this for every alphabetic character.
You are working too hard. No need to call any normalizer. No need for casting.
Avoid
charThe
chartype has been essentially broken since Java 2, and legacy since Java 5. As a 16-bit value,charis physical incapable of representing most characters.Code point
To work with individual characters, use Unicode code point integers. You will find code point methods on various classes such as
String,StringBuilder, andCharacter.Here is an example using code point numbers in hexadecimal within a
Stringliteral.Here is an example using appending code point numbers in decimal via
StringBuilder. 65 hex is 101 decimal, and 300 hex is 768 decimal.See that code run at Ideone.com.
Any Unicode-savvy text renderer software knows to combine the letter plus diacritic(s) for display. Learn about combining characters is digital typography at Wikipedia.
For more info, see: