2

I have a String representing a unicode character in Haskell, say "\\x00a0" and I want to convert it into Char ('\x00a0' in this case).

My last failed attempt is to read it as Int, then use Data.Char.chr to convert back to Char. It works for octal literals "\\xxx" but not on Unicode.

Can someone give me pointers on this?

1 Answer 1

5

Data.Char contains readLitChar, which will work on any Haskell string escape sequence (except for gaps and separators, of course):

Prelude Data.Char> readLitChar "\\x00a0" [('\160',"")] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.