RedGrittyBrick said:
moonhkt wrote:
Lothar Kimmeringer wrote:
moonhkt wrote:
Below not work.
[...]
Because it doesn't compile. What exactly doesn't work. Do you
get a wrong output, do you get an exception (you ignore in the
source you provided). A bit more information would really help
to be able to answer more than "something will be wrong in your
code". Regards,
Thank. I get below Example. But I can not get the UTF-8 char
code.
What do you mean by "UTF-8 char code"? Strictly speaking there is
no such thing. You might mean "Unicode code-point" or "sequence of
octets in UTF8-encoding"
[...]
Nothing in your program has anything to do with UTF-8 encoding.
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
Character[4] is l
Character[5] is c
Character[6] is o
Character[7] is m
Character[8] is e
Character[9] is
Character[10] is t
Character[11] is o
Character[12] is
Character[13] is R
Character[14] is o
Character[15] is s
Character[16] is e
Character[17] is
Character[18] is I
Character[19] is n
Character[20] is d
Character[21] is i
Character[22] is a
Character[23] is
Character[24] is ?
Character[25] is ?
Character[26] is .