Board index » jbuilder » Convert ASCII Code to String

Convert ASCII Code to String


2006-09-24 12:24:25 AM
jbuilder1
I've got an int that holds the ASCII code for a charactor and I need to
convert that to the char represented by that ASCII code. Example;
int myInt
char myChar
myInt = 68 // Ascii code for "D"
myChar = needs to be a D
But I haven't been able to figure out how to make that happen. I've found a
couple of ways to make myChar a string equal to 68, hahahaha but not quite
what I need. I'm working around external data and other people's code so I
don't really have the option to go back and start in a better way.
Can anyone help with how to assign the ASCII code in a int to a char?
Thanks,
Bernie
 
 

Re:Convert ASCII Code to String

String [] asciiCharacters = new String [] {65 other-values, "A", "B", "C",
"D");
0 is the first value (starting) in the array.....
fist array value can be a blank....
myChar = asciiCharacters[myInt];
you can use the following sites to build your asciiCharacters
www.walthowe.com/navnet/faq/ascitabl.html
www.newebgroup.com/academy/tables/ascii.htm
 

Re:Convert ASCII Code to String

Mehmet,
Thanks for the quick reply. I take it there is no way to directly convert
without the over head of a table? There is a way to get the ASCII code
from a charactor in Java, I figured there must be a way to turn an ASCII
code back into a charactor.
Bernie
"Mehmet F. Erten" < XXXX@XXXXX.COM >wrote in
Quote
Subject: Re: Convert ASCII Code to String
From: "Mehmet F. Erten" < XXXX@XXXXX.COM >
Newsgroups: borland.public.jbuilder.java.language
Reply-To: "Mehmet F. Erten" < XXXX@XXXXX.COM >

String [] asciiCharacters = new String [] {65 other-values, "A", "B",
"C", "D");

0 is the first value (starting) in the array.....
fist array value can be a blank....

myChar = asciiCharacters[myInt];

you can use the following sites to build your asciiCharacters

www.walthowe.com/navnet/faq/ascitabl.html

www.newebgroup.com/academy/tables/ascii.htm





 

{smallsort}

Re:Convert ASCII Code to String

Hi Bernie,
In Delphi we have the function Chr() which returns the string of a given
decimal code point, so Chr(68) would return "D".
Have you looked if Java does offer something similar?
Best wishes,
Michael
Bernie Hunt schrieb:
Quote
Mehmet,

Thanks for the quick reply. I take it there is no way to directly convert
without the over head of a table? There is a way to get the ASCII code
from a charactor in Java, I figured there must be a way to turn an ASCII
code back into a charactor.

Bernie



"Mehmet F. Erten" < XXXX@XXXXX.COM >wrote in
news: XXXX@XXXXX.COM :

>Subject: Re: Convert ASCII Code to String
>From: "Mehmet F. Erten" < XXXX@XXXXX.COM >
>Newsgroups: borland.public.jbuilder.java.language
>Reply-To: "Mehmet F. Erten" < XXXX@XXXXX.COM >
>
>String [] asciiCharacters = new String [] {65 other-values, "A", "B",
>"C", "D");
>
>0 is the first value (starting) in the array.....
>fist array value can be a blank....
>
>myChar = asciiCharacters[myInt];
>
>you can use the following sites to build your asciiCharacters
>
>www.walthowe.com/navnet/faq/ascitabl.html
>
>www.newebgroup.com/academy/tables/ascii.htm
>
>
>
>
>

 

Re:Convert ASCII Code to String

Hi Bernie,
You haven't said why having myChar=68 is "not quite what you want you need"
for a "D"
Does the following code do help with what you want?
for (int i=0; i<256; i++)
{
System.out.println("i=" + i + ", " + (char) i);
}
It simply casts the int to a char
Arth
"Bernie Hunt" < XXXX@XXXXX.COM >wrote in message
Quote
I've got an int that holds the ASCII code for a charactor and I need to
convert that to the char represented by that ASCII code. Example;

int myInt
char myChar
myInt = 68 // Ascii code for "D"
myChar = needs to be a D

But I haven't been able to figure out how to make that happen. I've found
a
couple of ways to make myChar a string equal to 68, hahahaha but not quite
what I need. I'm working around external data and other people's code so I
don't really have the option to go back and start in a better way.

Can anyone help with how to assign the ASCII code in a int to a char?

Thanks,
Bernie
 

Re:Convert ASCII Code to String

Arthur,
Please arrange for my stupid sign to be shipped to my work address. I
will affix it to my forehead as soon as it arrives.
I was trying
myChar = char(myInt);
rather than
myChar = (char) myInt;
Thanks to all for your paitent assistance!
Friends don't let friends code when they are tired!
Bernie
"Arthur Ore" < XXXX@XXXXX.COM >wrote in
Quote
Hi Bernie,

You haven't said why having myChar=68 is "not quite what you want you
need" for a "D"

Does the following code do help with what you want?

for (int i=0; i<256; i++)
{
System.out.println("i=" + i + ", " + (char) i);
}

It simply casts the int to a char

Arth

"Bernie Hunt" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>I've got an int that holds the ASCII code for a charactor and I need
>to convert that to the char represented by that ASCII code. Example;
>
>int myInt
>char myChar
>myInt = 68 // Ascii code for "D"
>myChar = needs to be a D
>
>But I haven't been able to figure out how to make that happen. I've
>found a
>couple of ways to make myChar a string equal to 68, hahahaha but not
>quite what I need. I'm working around external data and other
>people's code so I don't really have the option to go back and start
>in a better way.
>
>Can anyone help with how to assign the ASCII code in a int to a char?
>
>Thanks,
>Bernie


 

Re:Convert ASCII Code to String

Bernie Hunt wrote:
Quote
I've got an int that holds the ASCII code for a charactor and I need to
convert that to the char represented by that ASCII code. Example;

int myInt
char myChar
myInt = 68 // Ascii code for "D"
myChar = needs to be a D
myChar = (char)myInt;
--
Gillmer J. Derge [TeamB]