i have a string as below
string s =[104, 105, 103];
i want to extract the integer values and show it as character in Ascii format e.g
104=h
105=i
103=g
your advisez are appreciated .
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i have a string as below
string s =[104, 105, 103];
i want to extract the integer values and show it as character in Ascii format e.g
104=h
105=i
103=g
your advisez are appreciated .
Cross posted at string-int-char
(what is a cross post? do we post here or there?)
this code doesn't compile.
1. Strings are objects, and that means they start with a capital.
2. Strings can't be initialized like that ([104, 105, 103])
string s =[104, 105, 103];
This code would work,
AKA: String s = "104, 105, 103";
About converting strings to characters.
Java Convert Character to String
1) it seems far more useful to have an int array for this problem(up to you to understand what the teacher wants)
int[] myString = {104, 105, 103};
2) then all you have to do is use a "char" variable to convert it.
char oneLetter = (char)myString[0]; (this converts 104 into a char, which is 'h')
Hope this helps,
Jonathan
Last edited by JonLane; February 25th, 2012 at 01:38 PM. Reason: hyperlink fix