I'm making console based card game in f# and I'm struggling with displaying card suits using unicode chars. Mapping suit-to-char is represented as following function:
let suitSymbol = function
| Spades -> "\u2660"
| Clubs -> "\u2663"
| Diamonds -> "\u2666"
| Hearts -> "\u2665"
Displaying this using
printf "%s" <| suitSymbol Spades
works fine in fsi:
but when compiled using fsc.exe it displays diffrent (not suit) chars:
I've tried changing encoding of source file but to no effect. Is there any way for it to work when compiled?
EDIT (30.01.2017): Stuart's anwser was correct, but I couldn't get over fact, that It required to enter
chcp 65001
every time I wanted to run my game.
After studying ways of referencing DLLs within F#, I came up with following solution:
module Kernel =
[<DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
extern bool SetConsoleOutputCP(uint32 wCodePageID)
And in main function code I've added
[<EntryPoint>]
let main args =
Kernel.SetConsoleOutputCP 65001u |> ignore
It modifies code page for this process only, so other apps will behave normally.
In your command prompt you will need to change your code page like this:
chcp 65001
After some testing I was able to reproduce your issue, and this fixes it. Credit to @s952163
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With