-
November 16th, 2000, 06:45 AM
#1
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
-
November 16th, 2000, 07:34 AM
#2
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.
-
November 16th, 2000, 02:09 PM
#3
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
-
November 16th, 2000, 11:12 PM
#4
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?
-
November 17th, 2000, 02:19 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|