Pratik Rathod
Pratik Rathod

Reputation: 41

convert string to utf-8 in javascript

I am having hundeausführer (in German) text in URL and it is giving me as hundeausf%C3%BChrer in console.log. How can I convert hundeausf%C3%BChrer back to hundeausführer?

I tried

console.log(unescape(encodeURIComponent('hundeausf%C3%BChrer')));
console.log(decodeURIComponent(escape('hundeausf%C3%BChrer')));

but not getting a proper answer in the console log. Getting the same text as hundeausf%C3%BChrer

Anyone help me to solve this out?

Upvotes: 3

Views: 25952

Answers (2)

sjdm
sjdm

Reputation: 589

Use the decodeURI() function

console.log(decodeURIComponent('hundeausf%C3%BChrer'));

>>hundeausführer

Upvotes: 6

Deepak Preman
Deepak Preman

Reputation: 113

This works for me.

console.log(decodeURI('hundeausf%C3%BChrer'));

Upvotes: 2

Related Questions