Home > OS >  How do you compose an unescaped Unicode string in Haskell by parsing the escaped string?
How do you compose an unescaped Unicode string in Haskell by parsing the escaped string?

Time:05-31

I am parsing some text which might be "\u3200". Parsing this and converting to decimal, I know the integer sequence should be 12800. Now, I want to put this back together; I might do the following:

toPrintedChar x = return "\\x"    x

However, this returns an escaped sequence, and will not print the Unicode character associated with it. It is unclear to me how I can create a new string which does not have the escaped character.

I can create the string myself:

toPrintedChar x = return "\x12800"

and this does print the Unicode representation. I am wondering how I can do this generally? Thanks!

CodePudding user response:

To convert an integer value into a string made of that Unicode code point, it is enough to convert the number into a Char and then put it in a list. E.g.,

myString :: String
myString = [ toEnum 12800 ]
  • Related