🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #537

Re: Return the character from the respective ASCII code

#537
From: Paul Murray
Date: Thu, 17 Aug 2000 00:00
28 lines
1702 bytes
"Alan Boldock" <aboldock@boldenterprise.com.au> wrote in message
news:IJkm5.90417$N4.2170626@ozemail.com.au...

> > Did anyone of you know how to return the character from the ascii code
in
> > Java ? For example, 65 will return A !!

> cast to char!
>
> int characterAsInt = 65;
> System.out.println((char)characterAsInt);

This will convert from the unicode code, which is the same as ascii for
32-127. Really, for this kind of job you should use a character encoding,
which is described in the documentatiion for the java.lang package.

A "more correct" way to do this is

byte[] b = {65};
String s = new String(b, "US-ASCII");
System.out.println("Value " + b[0] + " encoded as ascii is " + s.charAt(0));

But why would you bother?

--------------------------------------------------------------
Repent! Quit your job! Slack off!
http://www.users.bigpond.com/pmurray/index-2.html
ICQ: 26066755
Technical Details
Message-ID: <5XSm5.32799$c5.91776@newsfeeds.bigpond.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <L45m5.99$ZC2.5192@nsw.nnrp.telstra.net> <IJkm5.90417$N4.2170626@ozemail.com.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,1654e71572b3fcd5
X-Google-Attributes: gid10d6db,public
From: "Paul Murray" <pmurray@nospam.bigpond.com>
Subject: Re: Return the character from the respective ASCII code
Date: 2000/08/17
Message-ID: <5XSm5.32799$c5.91776@newsfeeds.bigpond.com>
X-Deja-AN: 659355860
References: <L45m5.99$ZC2.5192@nsw.nnrp.telstra.net> <IJkm5.90417$N4.2170626@ozemail.com.au>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.3018.1300
X-Trace: newsfeeds.bigpond.com 966523713 139.134.123.221 (Fri, 18 Aug 2000 00:48:33 EST)
Organization: Telstra BigPond Internet Services (http://www.bigpond.com)
X-MSMail-Priority: Normal
NNTP-Posting-Date: Fri, 18 Aug 2000 00:48:33 EST
Newsgroups: aus.computers.java