Lukas Germerott
Lukas Germerott

Reputation: 361

String unicode with functions

I am trying to archive that a function is returning a unicode string and I want to log it into the console. But it just either displays the information about the function or just not a unicode string.

let test = () => "ÜTEST"

Js.log(test());

Js.log({j|$test()|j});

The first one just returns "ÃTEST" and the second one just returns information about the function itself.

Here is a working example: https://reasonml.github.io/en/try?rrjsx=true&reason=FAGwpgLgBBYM7QLxQBQEoqIHxQEQB2AVAUQGVDdhgApOAOhAHsBzFWBdNAbitoZZQBvAFYAfACTsI6UcIC+3IA

Upvotes: 0

Views: 143

Answers (1)

glennsl
glennsl

Reputation: 29126

You have to specify that the string is unicode at the point of creation, not at the point of use:

let test = () => {j|ÜTEST|j}
Js.log(test());

Also, string interpolation, as in {j|$test()|j}, only works with simple variable substitution. $test will be replaced by the contents of test, which is a function. It will not yield the result of calling test.

For more details, see the section on Unicode Support & Interpolation in the BuckleScript manual.

Upvotes: 5

Related Questions