I am working on creating a that involves using playing cards, but I am not sure what the best way to represent them textually is.

Here are some alternatives I have considered:

Note, the samples show a hand consisting of the Ace of Clubs, Ten of Clubs, Five of Hearts, Five of Spades, and Queen of Spades.

  • Represent rank with digits 1-9 and 10, and then J, Q, and K, and suit with S (spades), C (clubs), D (diamonds), and H (hearts):

    1C 10C 5H 5S QS
  • Use 0 to represent a ten:

    1C 0C 5H 5S QS
    • Each card is represented by the same number of characters.
    • Somewhat less readable.
  • Use numbers to represent all ranks:

    1C 10C 5H 5S 12S
    • Might be easier to parse, somehow.
  • Use . , , and to represent suit:

    1♣ 10♣ 5♥ 5♠ Q♠
    • Much easier to read.
    • Might be more difficult for languages that have problems with extended charsets.
  • Use A instead of 1, for an ace:

    A♣ 10♣ 5♥ 5♠ Q♠
    • Makes it a little bit prettier.
  • Some combination of these alternatives.

  • Use a custom character set to encode the cards.

    • Much more efficient.
    • Can't view it very easily.

I am rather partial to formatting them like A♣ 10♣ 5♥ 5♠ Q♠, but I would like to see what others think about this issue.

  • \$\begingroup\$ I like bullet #2 \$\endgroup\$
    – Kyle Kanos
    Jun 7, 2014 at 2:53
  • \$\begingroup\$ I'd go for the standard representation \$\endgroup\$ Jun 7, 2014 at 4:01
  • 1
    \$\begingroup\$ "T" for ten is not uncommon and it preserves a one-character rank indication which "10" does not. But for some classes of challenges maybe you don't want to make the input that much easier... \$\endgroup\$ Jun 7, 2014 at 4:22
  • 1
    \$\begingroup\$ That said, I don't think we need or even should have a standard representation for absolutely everything. The author of each challenge may have a reason for choosing a particular system and who are we to gainsay that? \$\endgroup\$ Jun 7, 2014 at 4:25

2 Answers 2


KISS. Sticking to ASCII makes it simpler: the byte representations will be the same in ISO-8859-1, UTF-8, and MacRoman, so people don't have to worry about ensuring that they're using the correct character encoding. (Of course, they should as a matter of principle, but this site isn't really about best practices).

Of the various ASCII options, the one I'm more familiar with from my bridge-playing days is A23456789TJQK CDHS, but the simplest for inter-program communication is probably to number the cards from 0 to 51.

However, there's nothing which requires you to use the same format for inter-program communication and for presentation to the user. Although I recommend using ASCII for the communication, the scoring program could be made more polished by using A23456789TJQK ♠♡♢♣ in its logs.


Might I suggest Unicode (6+)?


🂡 🂱 🃁 🃑
🂢 🂲 🃂 🃒
🂣 🂳 🃃 🃓
🂤 🂴 🃄 🃔
🂥 🂵 🃅 🃕
🂦 🂶 🃆 🃖
🂧 🂷 🃇 🃗
🂨 🂸 🃈 🃘
🂩 🂹 🃉 🃙
🂪 🂺 🃊 🃚
🂫 🂻 🃋 🃛
🂬 🂼 🃌 🃜
🂭 🂽 🃍 🃝
🂮 🂾 🃎 🃞
🂠 🃏 🃟

edit This is a screenshot from Chromium on Ubuntu 14.04 of what it should look like.

enter image description here

  • \$\begingroup\$ In a lot of fonts these are either unsupported or really hard to distinguish unless you use a large font size. \$\endgroup\$ Jun 7, 2014 at 10:34
  • 6
    \$\begingroup\$ I see boxes because I don't have the appropriate font package \$\endgroup\$
    – Kyle Kanos
    Jun 7, 2014 at 11:19
  • \$\begingroup\$ On what platform are you? \$\endgroup\$
    – gxtaillon
    Jun 7, 2014 at 15:30
  • \$\begingroup\$ The text and the image look identical to me (FF on Ubuntu), and I haven't done any fancy font stuff, so these must be supported by default on at least some systems. That said, I don't think these would be the best idea because of lack of support, at least on some platforms. \$\endgroup\$
    – Doorknob
    Jun 7, 2014 at 18:30
  • \$\begingroup\$ Renders OK for me on Ubuntu 14.04, but not on OSX 10.9.3. I'm downvoting this because I don't think its worth going to all this trouble, only to have hearts and diamonds be coloured black. \$\endgroup\$ Jun 7, 2014 at 20:14
  • \$\begingroup\$ I'm using Scientific Linux 6.4. I don't have many Unicode fonts installed because I really don't need them & the extra fonts are really just bloat-ware, IMO. \$\endgroup\$
    – Kyle Kanos
    Jun 8, 2014 at 14:45
  • \$\begingroup\$ Aside: I'm really impressed that Unicode has glyphs for the "Cavalier" cards in bizarre tarot decks. \$\endgroup\$
    – Kaz Dragon
    Jun 19, 2014 at 10:01
  • \$\begingroup\$ Chrome, Windows 7: squares. Seems only Linux supports these glyphs as of now. \$\endgroup\$ Jul 1, 2014 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .