Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java String from ASCII value
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Martin




PostPosted: Thu Jul 21, 2005 8:16 pm   Post subject: Java String from ASCII value

How do I create a string containing the character represented by an int ASCII value?
I've tried casting from int to char, but apparently that doesn't work.
ie.
x = 97;
System.out.println (ASCIIString(x)); //print 'a'
Sponsor
Sponsor
Sponsor
sponsor
Martin




PostPosted: Thu Jul 21, 2005 8:22 pm   Post subject: (No subject)

Figured it out. Java is gross.

Conversion from an int to a String.

int x = 97;
System.out.println (((char) x) + "");
rizzix




PostPosted: Thu Jul 21, 2005 8:28 pm   Post subject: (No subject)

eh? why not simply...
Java:
char a = 97;
System.out.println(a);


oh, but if you want a String yea just concatenate it with +""
or...
Java:
String a = new String(new char[]{97});


or best...
Java:
String a = Character.toString(97);
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: