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
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
posted 14 years ago
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:\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
Marilyn de Queiroz
posted 14 years ago
Try putting an import statement at the top of your code, Maureen.
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 ]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
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.
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 ]
"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
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad: