Results 1 to 5 of 5

Thread: ChrW()

  1. #1

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    ChrW()

    Dear Java developer,

    I am VB.net developer and now i try to study java.
    in VB.net, there is a function ChrW() that convert from Unicode code to the Character. ex. ChrW(65) it will return A.
    Is there any function in Java similar to this function?

    Thirith
    ជីន ច័ន្ទធិរិទ្ធ៖ពេលវេលាពុំដែលរង់ចាំអ្នកឡើយ!Time never wait you!

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: ChrW()

    A direct cast should do the trick for you

    Code:
    char ch = (char) 65;
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Addicted Member thirith's Avatar
    Join Date
    Oct 2004
    Posts
    196

    Re: ChrW()

    Quote Originally Posted by ComputerJy
    A direct cast should do the trick for you

    Code:
    char ch = (char) 65;
    Thank you,

    what about the Unicode? Unicode have 2 bytes, 4 bites. It can work with this type.
    ជីន ច័ន្ទធិរិទ្ធ៖ពេលវេលាពុំដែលរង់ចាំអ្នកឡើយ!Time never wait you!

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: ChrW()

    Characters in java are stored as Unicode by default, but in the case of casting from an integer to an char the integer value is considered ASCII code
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: ChrW()

    Java's Unicode escape sequences are in the form '\uXXXX'.

    If you are using Java 1.4 or earlier then the 's.length()' gives the number (16 bit) of characters in a string or a single character. Characters with Unicode values greater than '\uFFFF' cannot be represented.

    If you are using Java 1.5 string/character representing on UTF-16 encoding. So you can read characters above '\uFFFF' , as pairs of characters .

    To determine the length of such a string/character,

    Code:
    int length = Character.codePointCount (str, 0, str.length ());
    Read the Java 5 documentation to find more about the code point scheme.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width