CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 1999
    Location
    India.
    Posts
    81

    how to get ASCII value of a character?

    Hi,
    I have to get an ascii value of a character. Is there any function?
    Please help.
    Thanks in advance
    Monika


  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: how to get ASCII value of a character?

    Java uses Unicode rather than ASCII, and to get the Unicode value of a char you need to use:int unicodeVal = Character.getNumericValue(myChar);

    Dave

    To email me remove '_spamjam' from my email address
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  3. #3
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: how to get ASCII value of a character?

    What do you mean by ASCII value?
    The Character.getNumbericValue() method returns an int 1 for the character '1' and an int 10 for 'a'.
    Another possible value would be int 49 for a '1' and int 97 for 'a'.

    Which value is wanted?

    Norm

  4. #4
    Join Date
    Jul 1999
    Location
    India.
    Posts
    81

    Re: how to get ASCII value of a character?

    Hi,
    Thanks a lot for your reply.
    What I want is,
    65 for A, 66 for B, or 48 for 0 - according to the ASCII set.
    Is there any function that can get me this?



  5. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: how to get ASCII value of a character?

    Here's a sample program:
    // Test conversion of Unicode to ASCII/int

    class ShowNumberic {
    public static void main(String[] args) {
    int x = "1".charAt(0); // String to Character to int
    int y = 'A'; // Character to int
    byte[] z = "B|".getBytes(); // String to bytes
    System.out.println("1=" + x + " A=" + y + " B=" + z[0] + " |=" + z[1]);
    }
    }



    Norm

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

Featured