This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Displaying char values from 128 to 160 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Displaying char values from 128 to 160" Watch "Displaying char values from 128 to 160" New topic
Author

Displaying char values from 128 to 160

pankaj bansal
Greenhorn

Joined: Mar 07, 2001
Posts: 20
Hi Everybody
I'm trying to display char values from 1 to 300 but between 128-159 it gives me '?' for all. People say its bcoz java is unicode. But then what bout 160 and other higher values?
A sample code would be appreciated to display all values of char.
thanx
pankaj
------------------

SCJP2
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The range of a char i Java is 0 to 65535 - using an int won't make a difference unless you go outside this range. The main reason you might not see a representation for a given character is that your terminal simply doesn't know how to display that character. Also some characters may not have definitions. You can learn more at www.unicode.org - in particular check out the code charts. Enjoy...


"I'm not back." - Bill Harding, Twister
pankaj bansal
Greenhorn

Joined: Mar 07, 2001
Posts: 20
Thanx Jim
Can u tell me how to install the unicode characters so that I can get the those char values.
Thanx in advance
Pankaj
------------------
SCJP2
Matts Smith
Ranch Hand

Joined: Feb 03, 2001
Posts: 113
Pankaj : It is a functionnality of the writer classes. chars 128-159 are different depending on the OS. The writer classes will print ? for those chars...
try using a FileOutputStream in the following manner

later
Matts Smith
Ranch Hand

Joined: Feb 03, 2001
Posts: 113
oops my mistake...
It's not the Writer classes... it is the char type itself that's behaving this way.
sorry
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Look at the code charts I recommended. In particular Latin-1 Supplement tells you what all the codes from 0x0080 to 0x00FF are - the includes 0x0080 - 0x00A0, or 128-160 in decimal. It turns out none of these characters have printable values in Unicode. I'm not sure exactly what these chars are used for- see the later pages for the names these chars have, such as 131 signifies "NO BREAK HERE". So don't worry about trying to print these; you can't. (Not visibly at least.)

[This message has been edited by Jim Yingst (edited March 16, 2001).]
pankaj bansal
Greenhorn

Joined: Mar 07, 2001
Posts: 20
Thanx Matts Thanx Jim
I tried Matts' code and it runs perfectly alright and displayed me the char values between 128-159. But it is not clear to me that when I displayed that in the SOP it gives the same old o/p. Why?
Jim as u said these r not printable characters then how is it able to save in the file?

------------------
SCJP2
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
I suppose to display UNICODE characters you need a proper font, to print them � printer driver. Not sure about typing � keyboard driver? I use keyboard driver to type Russian texts, but our letters fit 101 key set pretty well . UNICODE keyboard drivers may use limited subset for particular language, but it is only my guess. This text may help with displaying: http://www.unicode.org/help/display_problems.html

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
Mapraputa Is
Leverager of our synergies
Sheriff

Joined: Aug 26, 2000
Posts: 10065
... and this can give a clue for printing: http://www.pef.uni-lj.si/~mitjag/pef/unicode.html
Skip Slavic (SLOVENSKI?) text and go directly to �SYMPTOMS� section - �SYMPTOMS� are in English for some reasons .
pankaj bansal
Greenhorn

Joined: Mar 07, 2001
Posts: 20
Thanx Is
I appreciate ur response but I don't think that has any relation with printer driver. B'coz I want to display on the screen and anyway I can take the printout of the file in which the characters r stored. But the problem remains the same that's via System.out.println() the desired o/p is not coming.
Bye
pankaj
------------------
SCJP2
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
OK Pankaj, you've written values to a file. This is possible because each Unicode char is a two-byte value, and OutputStream has a method which allows you to store that value in a file. But what do the numbers mean? In Unicode, they refer to unprintable characters. Really, they do - look at the documentation. But when you give the file a .txt suffix, you're telling Windows to treat the file as a text file. Which means Windows will assume that you're using its standard text encoding scheme, most likely Western European. Which, as it happens, assigns completely different meanings to characters 128-160. Not to mention the others from 161-255. (The first 128 are probably the same in both schemes, as they come from the old ASCII codes.) So the fact that you look at the file using Notepad or some other application and "see" characters doesn't tell you anything about what the values mean in Unicode, unless you use an application that understands Unicode.
Try this. Download the latest version of Internet Explorer, 5.50. (You can probably do this with other browsers too, but I make no promises.) Rename "file.txt" as "file.html", and double-click on it. Go to View -> Encoding and see the list of encodings available. One will be already selected for you - that's what you're seeing by default. There should be a listing for Unicode/UTF-8 - select this. The characters 128-160 shoud now be showing up as boxes, or maybe question marks, indicating that they don't correspond to printable characters. Not in Unicode anyway. QED. For fun, print a whole list of chars 0-255, and try looking at them through different encodings. Enjoy.

[This message has been edited by Jim Yingst (edited March 17, 2001).]
pankaj bansal
Greenhorn

Joined: Mar 07, 2001
Posts: 20
A million thanx Jim. I got the point.
Thanx once again.
Bye
Pankaj
------------------
SCJP2
Tom Pollak
Greenhorn

Joined: Sep 26, 2001
Posts: 1
Just want to thank you for a topic NOT covered sufficiently re displaying unprintable characters. Your solution works!!
Tom.
Originally posted by Matts Smith:
[B]Pankaj : It is a functionnality of the writer classes. chars 128-159 are different depending on the OS. The writer classes will print ? for those chars...
try using a FileOutputStream in the following manner

later[/B]

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Displaying char values from 128 to 160
 
Similar Threads
Problem converting C/C++ unsigned char to JAVA
Variations of Character outpot
similarity between string and wrapper objects?
transfering Euro (?) character
Printing unicode character