Dealing with UTF-8 input in JavaScript (SpiderMonkey)

Modified on Thu, 9 Jul at 3:19 PM

In SpiderMonkey, input from readline() does not handle UTF-8 data properly. If you are having trouble reading UTF-8 input, try something like the following.


function fromUTF8(str) {
    return decodeURIComponent(escape(str));
}

const line = fromUTF8(readline());

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article