Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
729 views
in Technique[技术] by (71.8m points)

unicode - Combining accent and character into one character in java 7

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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("u0069u0307", Form.NFC).charAt(0);

For double dots use u0308.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...