英文:
Convert string with encoded character to readable string in Javascript
问题
Desired output: "Università di Parma"
英文:
An API is returning string with special characters in this form:
"Universit\xc3\xa0 di Parma"
\xc3\xa0 means the character "à"
How can I convert this string into a readable form with JavaScript code?
Thank you !
Input: "Universit\xc3\xa0 di Parma"
Desidered output: "Università di Parma"
答案1
得分: 1
Use the escape()
method with decodeURIComponent.
const original = 'Università di Parma';
const result = decodeURIComponent(escape(original));
console.log(result);
英文:
Use the escape()
method with decodeURIComponent.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
const original = 'Universit\xc3\xa0 di Parma';
const result = decodeURIComponent(escape(original));
console.log(result);
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论