moonhkt wrote:
Hi All I want output the Character in the string one by one.
Now,codePointAt just print the Code points value.
Why not use String's length() and CharAt() methods?
I assume you can disregard characters outside Unicode's Base
Multilingual Plane (BMP) - if not, I think you'll have to check for
surrogate pairs. Characters outside the BMP are too big for a char.
-------------------------------------8<-----------------------------------
public class UnicodeChars {
public static void main(String[] args)
throws UnsupportedEncodingException {
// I want console output in UTF-8
PrintStream sysout = new PrintStream(System.out, true, "UTF-8");
// \u00fc is LATIN SMALL LETTER U WITH DIAERESIS;
// \u34d7 is a character in CJK Unified Ideographs Extension A.
// \uD834\uDD1E" are the surrogate pair for character U+1D11E.
// U+1D11E is MUSICAL SYMBOL G CLEF;
String a = "\u00fc\u34d7Welcome to Rose India \uD834\uDD1E.";
int n = a.length();
sysout.println("GIVEN STRING IS=" + a);
sysout.printf("Length of string is %d%n", n);
sysout.printf("CodePoints in string is %d%n",
a.codePointCount(0,n));
for (int i = 0; i < n; i++) {
sysout.printf("Character[%d] is %s%n", i, a.charAt(i));
}
}}
-------------------------------------8<-----------------------------------
GIVEN STRING IS=?????Welcome to Rose India ????.
Length of string is 27
CodePoints in string is 26
Character[0] is ??
Character[1] is ???
Character[2] is W
Character[3] is e