5

I am trying to write a java code that returns a single character combining both a character and an accent. The actual result of combining is a string and not one single character. The following is a simple method to illustrate what I am trying to do. Thank you

private char convert (char c)
{
 if (c == '\u0130')
 {
  return '\u0069 \u0307'; // If the return value is String I get i. 
}                         //I need small i double dot
else return c;
}
Christophe Roussy
  • 16,299
  • 4
  • 85
  • 85
Bionix1441
  • 2,135
  • 1
  • 30
  • 65
  • if I understand correctly you want to return a string? why not private String convert(char c) and returning "\u0069" + "\u0307"? – 12dollar Mar 05 '15 at 08:46

1 Answers1

14

Normalizer can decompose/compose your character as you like:

String decomposed = Normalizer.normalize(String.valueOf('ï'), Form.NFD);

result are two character (i, double-dot)

String composed = Normalizer.normalize(decomposed, Form.NFC);

result is one character (ï)

If I understand you correctly you seek

return Normalizer.normalize("\u0069\u0307", Form.NFC).charAt(0);

For double dots use \u0308.

CoronA
  • 7,717
  • 2
  • 26
  • 53