Results 1 to 9 of 9
Thread: Unicode
- 09-20-2013, 06:23 PM #1
Senior Member
- Join Date
- Aug 2013
- Location
- Sweden
- Posts
- 163
- Rep Power
- 8
Unicode
Hello!
I'm writing a card game called "Twenty-one", and for that I wanted the card symbols (Hearts, diamonds etc.) which are available in Unicode. So I filled a Vector<String> with cards and with the symbols which were presented on Unicode's website, but when I try to output them I only get a question mark instead of the card symbols. So I'm wondering if I need to import something to be able to see them. I'm using Eclipse btw. Here is my code:
Java Code:Vector<String> cards = new Vector<String>(); cards.addAll(Arrays.asList("\u2664 E", "\u2664 2", "\u2664 3", "\u2664 4", "\u2664 5", "\u2664 6", "\u2664 7", "\u2664 8", "\u2664 9", "\u2664 10", "\u2664 Knight", "\u2664 Queen", "\u2664 King", "\u2665 E", "\u2665 2", "\u2665 3", "\u2665 4", "\u2665 5", "\u2665 6", "\u2665 7", "\u2665 8", "\u2665 9", "\u2665 10", "\u2665 Knight", "\u2665 Queen", "\u2665 King", "\u2666 E", "\u2666 2", "\u2666 3", "\u2666 4", "\u2666 5", "\u2666 6", "\u2666 7", "\u2666 8", "\u2666 9", "\u2666 10", "\u2666 Knight", "\u2666 Queen", "\u2666 King", "\u2667 E", "\u2667 2", "\u2667 3", "\u2667 4", "\u2667 5", "\u2667 6", "\u2667 7", "\u2667 8", "\u2667 9", "\u2667 10", "\u2667 Knight", "\u2667 Queen", "\u2667 King"));
- 09-21-2013, 06:06 AM #2
Senior Member
- Join Date
- Jan 2009
- Location
- CA, USA
- Posts
- 271
- Rep Power
- 13
Re: Unicode
Where are you printing the results? Eclipse console? Try in cmd line. Or writing it out to a file and viewing it in notepad.
Edit:
Did some research, found out Java is a little odd with different encodings. Try doing it this way:
String str = new String(new byte[] { (byte)'\u2664', ' ', 'E' }, "utf-8");
System.out.println(str);
And see if it suits your needs. Not very nice looking... I'm sure there is a better way to do it, though.Last edited by AndrewM16921; 09-21-2013 at 06:14 AM.
- 09-21-2013, 10:33 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Unicode
What happens if you print the following in your Eclipse console? (it prints fine for me)
Java Code:System.out.println("\u2664 E");
JosBuild a wall around Donald Trump; I'll pay for it.
- 09-21-2013, 11:32 AM #4
Senior Member
- Join Date
- Aug 2013
- Location
- Sweden
- Posts
- 163
- Rep Power
- 8
Re: Unicode
@ AndrewM16921 I'm printing the results in the Eclipse console, yes.
I will try doing that, thanks :) It is going to be tedious doing it for every element in my string vector though...
@ JosAH It just prints the \u2664 part as a question mark, but the rest is fine. Strange thing though is that when I run the program in BlueJ instead, it works fine.Last edited by Zelaine; 09-21-2013 at 11:40 AM.
- 09-21-2013, 04:00 PM #5
Re: Unicode
(byte)'\u2664'If you don't understand my response, don't ignore it, ask a question.
- 09-21-2013, 05:05 PM #6
Senior Member
- Join Date
- Jan 2009
- Location
- CA, USA
- Posts
- 271
- Rep Power
- 13
- 09-21-2013, 07:35 PM #7
Senior Member
- Join Date
- Aug 2013
- Location
- Sweden
- Posts
- 163
- Rep Power
- 8
Re: Unicode
So how does one make them visible then? They're visible in BlueJ, but strangely enough not in Eclipse...
- 09-21-2013, 08:02 PM #8
Senior Member
- Join Date
- Jan 2009
- Location
- CA, USA
- Posts
- 271
- Rep Power
- 13
Re: Unicode
Window > Preferences > General > Workspace > set text file encoding to UTF-8.
- 09-21-2013, 08:54 PM #9
Senior Member
- Join Date
- Aug 2013
- Location
- Sweden
- Posts
- 163
- Rep Power
- 8
Similar Threads
-
Help in Unicode
By justbeller in forum NetBeansReplies: 0Last Post: 01-29-2011, 07:43 PM -
wat is the unicode of '?' ? 63 or 128
By Jagdeesh123 in forum New To JavaReplies: 1Last Post: 12-09-2010, 09:49 AM -
Unicode(UTF-8) to PDF
By karasatishkumar in forum Advanced JavaReplies: 0Last Post: 03-24-2010, 11:59 AM -
Lucene with unicode
By goms in forum LuceneReplies: 1Last Post: 02-02-2010, 02:20 PM -
SWT 2D Unicode Example
By Java Tip in forum SWT TipsReplies: 0Last Post: 06-28-2008, 10:21 PM
Bookmarks