File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ASCII Conversion Problem - emdash sign Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ASCII Conversion Problem - emdash sign" Watch "ASCII Conversion Problem - emdash sign" New topic
Author

ASCII Conversion Problem - emdash sign

Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
Dear Friends,
I'm trying to add ascii values to a 2d array. but when I'm trying to add 151 ascii character to the string array it adds it as a '?' instead of 'emdash' sign. I couldn't figure out this. This works for other ascii values perfectly.


how can I add emdash sign to a string array without any issue?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13869
    
  10

151 is not a valid code for an ASCII character; ASCII characters have codes between 0 and 127.

What your code does is take Unicode character U+0097 (97 hex = 151 decimal) and convert that to a string. I've looked up Unicode character U+0097 on www.unicode.org and it's some sort of control character, so it's not surprising that it is shown as "?". It's certainly not an "emdash" character.

I looked up the Windows-1252 encoding and indeed, in that encoding the character 0x97 looks like a long dash. But Windows-1252 is not ASCII and not Unicode.

If you want to specify characters according to the Windows-1252 encoding, you'll need to decode from that encoding, instead of directly interpreting the characters as Unicode characters. Something like this should work, although I haven't tested it:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3946
    
  17

Character codes in java are Unicode codes, not ASCII codes. The Unicode character for emdash is 8212 (in decimal) I think. There isn't an ASCII code for emdash as far as I could find... The only association to 151 and the em dash is the Windows insertion code, but I don't know what reference they use to get that number.


Steve
Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
Jesper de Jong wrote:151 is not a valid code for an ASCII character; ASCII characters have codes between 0 and 127.

What your code does is take Unicode character U+0097 (97 hex = 151 decimal) and convert that to a string. I've looked up Unicode character U+0097 on www.unicode.org and it's some sort of control character, so it's not surprising that it is shown as "?". It's certainly not an "emdash" character.

I looked up the Windows-1252 encoding and indeed, in that encoding the character 0x97 looks like a long dash. But Windows-1252 is not ASCII and not Unicode.

If you want to specify characters according to the Windows-1252 encoding, you'll need to decode from that encoding, instead of directly interpreting the characters as Unicode characters. Something like this should work, although I haven't tested it:




Thanks Jesper it's working..bravo ... I spent half a day for this ...Thanks again
Gihan Pandigamage
Ranch Hand

Joined: Aug 23, 2009
Posts: 60
Steve Luke wrote:Character codes in java are Unicode codes, not ASCII codes. The Unicode character for emdash is 8212 (in decimal) I think. There isn't an ASCII code for emdash as far as I could find... The only association to 151 and the em dash is the Windows insertion code, but I don't know what reference they use to get that number.


Thanks steve problem solved. Jesper's code snippet working
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ASCII Conversion Problem - emdash sign
 
Similar Threads
Array help
StringTokenizer
byte array question
Database to multi-dimensional array problem
iterating with a scriptlet, can't get the values into js arr