简体   繁体   English

从 unicode 十六进制解码为字符串

[英]decode from unicode hex to string

When I load my data from my model (asp.net model) if the string is in another language (Russian for example), I'm getting the unicode hex code of the chars.当我从 model(asp.net 模型)加载数据时,如果字符串是另一种语言(例如俄语),我得到的是字符的 unicode 十六进制代码。 How can I convert them to a normal string?如何将它们转换为普通字符串? The problem isn't from the javascript encoding, it's from loading it from the model.问题不在于 javascript 编码,而在于从 model 加载它。 I tried using a lot of functions from the forum but none worked: Here is an example of a value I should get:我尝试使用论坛中的很多功能,但没有一个起作用:这是我应该得到的值的示例:

Петър

And here is what I'm actually getting:这是我实际得到的:

Петър

 const sequence = 'Петър' const charCode = sequence.split(/[;\s]+/g) // remove empty.filter((v) => v) // &#x41F -> 0x41F -> number.map((v) => Number.parseInt(v.replace(/&#/, '0'))) console.log( String.fromCharCode(...charCode) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM