aspose file tools*
The moose likes Beginning Java and the fly likes All I want is a � (pound) sign.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "All I want is a � (pound) sign.." Watch "All I want is a � (pound) sign.." New topic
Author

All I want is a � (pound) sign..

Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I am trying to display the � sign on screen.

My code is:


I've looked up Literals and couldn't find it listed.

Is anyone able to help or alternatively point me in the right direction.

The output I am getting to screen is:


Balance: �135.64
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
You don't need to do anything special. a printline of "�xyz" prints it.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

The Unicode value for the pound sign is \u00A3. In decimal, this is 163, which typically represents an accented "u" (�) in ascii extended. This is what you're seeing.

How these characters display depends on the environment. In my XP Command window, a println of "�xyz" displays �xyz. However, in Eclipse, this displays as �xyz. So although you're seeing � in the Command window, I expect that you would see � in a Java GUI.

Unfortunately, I don't know how to get the pound sign to display in the Command window. The extended ascii value for the pound sign is usually 156, so I expected char p = 156 to display as �, but it displays a question mark instead



ASCII: http://www.lookuptables.com/
Unicode: http://www.unicode.org/charts/PDF/U0080.pdf
[ February 26, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
On my terminal window 0xA3 gives me a £ sign


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Marilyn de Queiroz:
On my terminal window 0xA3 gives me a £ sign

Hmmm... What platform are you on, and how exactly are you coding this? I tried the following, but still get the accented u (in the Windows XP Command prompt):

char p = 0xA3; //decimal 163
System.out.println("0xA3: " + p);
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
I also tried the following:



And still got the accented u on screen!
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Had a play with more extended codes. No luck though. My output resulted in the following with the relevant codes:

? This was 156
? This was 158
? This was 159
� This was 160
� This was 163
� This was 172
┤ This was 180
? This was 151
? This was 128

Can anyone see a pattern? Or help further?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
The term "extended ascii" is pretty much useless nowadays. Do not trust anything or anyone which talks about "extended ascii" as if it means something. We're long past the point when ascii was enough, and there's more than one form of "extended ascii". You need to find out exactly what the default encoding is on your system - that's what your system speaks. Unfortunately Sun did not bother to create a simple method to do this, even though it's really useful information for you to have when debugging encoding problems. Try this:

I suspect that the encoding on your system will turn out to be one in which £ cannot be represented. Not all characters can be represented on all systems by default. Have you ever seen £ printed in a command window on your system? You may need to abandon System.out.println() and instead send your output to something that knows what a £ is. Good candidates for this would be a web browser (where you can represent £ as "£" - that's how I posted this) or some sort of JTextComponent (which understands Unicode much better than System.out does). Alternately, you may be able to reset your platform default encoding to something which supports £. Let us know what the default encoding is, and what kind of system you're on, and we may be able to help better.
[ February 27, 2005: Message edited by: Jim Yingst ]

"I'm not back." - Bill Harding, Twister
Maureen Charlton
Ranch Hand

Joined: Oct 04, 2004
Posts: 218
Firstly, many thanks for your response - much appreciated.

The operating system I am on is Windows 2000

I tried your suggestion and received the following error:

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\maureen2>cd \

C:\>cd java

C:\java>cd bankaccount

C:\java\BankAccount>notepad Current.java

C:\java\BankAccount>javac TestClass.java
.\Current.java:138: cannot resolve symbol
symbol : class OutputStreamWriter
location: class Current
System.out.println(new OutputStreamWriter(new ByteArrayOutputStream()).getEncodi
ng());
^
.\Current.java:138: cannot resolve symbol
symbol : class ByteArrayOutputStream
location: class Current
System.out.println(new OutputStreamWriter(new ByteArrayOutputStream()).getEncodi
ng());
^
2 errors

C:\java\BankAccount>
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Try putting an import statement at the top of your code, Maureen.

import java.io.*;

I can get a pound sign by typing alt-156, but not by typing alt-0156 and not (so far) by using System.out.println()
[ February 28, 2005: Message edited by: Marilyn de Queiroz ]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If you don't see £ in your Windows console, try changing the font of the window. Click the window's icon (left side of title bar), select Properties, and switch to Font tab. I use Lucida Console (I find it's the easiest on my eyes) and can see the £ when I type Alt-156.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Jim Yingst:
The term "extended ascii" is pretty much useless nowadays...

Yeah, that's why I qualified it with words like "typically" and "usually." I referenced extended acsii only because I think it explains why the accented u is appearing, but I didn't go down the path of different extended sets.

From a practical standpoint -- assuming we're stuck with a Windows console -- I suggest abandoning the symbol and using the acronym, "GBP."
[ February 28, 2005: Message edited by: marc weber ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: All I want is a � (pound) sign..