Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a string like "36193657363436093648359236573648362136573591" which I want to decode it. I tried search the unicode library without success.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
585 views
Welcome To Ask or Share your Answers For Others

1 Answer

Prelude> putStrLn "36193657363436093648359236573648362136573591"
???????????

Note that you don't actually have the string "36193657363436093648359236573648362136573591" – rather, you have the UTF-32 string ???????????, for which "36193657..." happens to be a ASCII-compliant literal. By default, GHCi uses the Show instance to display results, which doesn't so much show things as spit out literals that can be used as Haskell code for the thing. It's conservative in terms of unicode. That's why

Prelude> "???????????"
"36193657363436093648359236573648362136573591"

On the other hand, the putStrLn, putChar, hPutStr etc. functions will just dump the string itself in UTF-8 rather than an ASCII-safe representation thereof.

If you're actually reading the escaped string from a file or something, you can simply read it:

Prelude> s <?- getLine
"36193657363436093648359236573648362136573591"
Prelude> s
""\3619\3657\3634\3609\3648\3592\3657\3648\3621\3657\3591""
-- Note double escaping, because I'm showing a string that contains a string literal.
Prelude> putStrLn $ read s
???????????


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...