Results 1 to 4 of 4
  1. #1
    Zoidy is offline Member
    Join Date
    Oct 2010
    Posts
    4
    Rep Power
    0

    Default Extracting unicode from char

    Hello every one,

    I am trying to create a small program that askes for a single input, and it in turn prints out what it is.

    f.ks if a upper case letter is inputed by the user, the printout will state "That is an upper case letter"

    How then do I get the unicode value from that letter? uppercase 65-90, lowercase 97-122.

    the point of getting the unicode is so that I can do a switch staement to decide the printout.

    Thanks in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    You can turn the string into a char (if it isn't one already) and then do an if against it with ints... (if mychar < 91 and mychar > 64 then this is uppercase).

    Or, use Character which has isUpperCase and isLowerCase methods.

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    448
    Rep Power
    6

    Default

    you can use simple if else instead of Switch.
    Mak
    (Living @ Virtual World)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Zoidy View Post
    Hello every one,

    I am trying to create a small program that askes for a single input, and it in turn prints out what it is.

    f.ks if a upper case letter is inputed by the user, the printout will state "That is an upper case letter"

    How then do I get the unicode value from that letter? uppercase 65-90, lowercase 97-122.

    the point of getting the unicode is so that I can do a switch staement to decide the printout.

    Thanks in advance
    Chars are small (two byte) unsigned ints. e.g. you can do:

    Java Code:
    char letter= (char)65;
    The cast is needed because the literal number is interpreted by the compiler as if it were a normal (four byte) int. Chars can also be represented symbolically:

    Java Code:
    char letter= 'A';
    The classification of characters (letters, digits etc.) is best left to the Character class. There are more uppercase letters than just A ... Z. There are even letters that don't have a lowercase representation (just uppercase). Leave all that potential confusion to the Character class, it knows best.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Extracting jpg from animated gifs
    By Maz in forum Java 2D
    Replies: 3
    Last Post: 05-05-2011, 12:29 PM
  2. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 09:24 PM
  3. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 05:48 AM
  4. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 12:49 PM
  5. Extracting JAR file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:17 AM

Posting Permissions

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