![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
ascii value to char
Can someone please tell me what's wrong with this code? The array has been declared already. I just don't know how to convert this ascii value to char. if i needed to convert the ascii value to a string I would do:
int i = 65; String aChar = new Character((char)i).toString(); // output "a" However, i need to convert to a char value. int countascii = 65;
char aChar = ' ';
aChar = new Character ((char) countAscii);
letters [0] [0] = aChar;
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 3
![]() |
Unlike c#, the "char" type in Java is not the same as its "Character" class. The Character class is a wrapper around the char type. All you need to do is explicitly convert int to char:
aChar = (char) countAscii; |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
thanks!
__________________
Death smiles at us all. All a man can do is smile back. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|