我有一串八进制转义,我需要转换为韩文文本 - 不知道如何 [英] I have a string of octal escapes that I need to convert to Korean text - not sure how
本文介绍了我有一串八进制转义,我需要转换为韩文文本 - 不知道如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现了一个类似的问题:
但我无法弄清楚如何在.net c# p>
问题:我有一个数据库中的字符串 - \354\202\254\354\232\251\354\236\ 220\354\203\201\354\204\270\354\240\225\353\263\264\354\236\205\353\\ \\240\245
应该翻译成 - 用户名상세정보입력
任何帮助都会很大赞赏!
解决方案
转换涉及到许多步骤:
- 从源字符串中提取单个八进制数(例如
354
)。 - 转换每个八进制字符串表示为其十进制等效作为一个字节。
- 将字节序列解码为UTF-8。
实现:
string source = @\354\202\254\354\232\251\\ \\ \\264\354\236\205\353\240\245\" ;
byte [] bytes = source.Split(new [] {'\\'},StringSplitOptions.RemoveEmptyEntries)
.Select(s =>(byte)Convert.ToInt32 (s,8))
.ToArray();
string result = Encoding.UTF8.GetString(bytes); //사용자상세정보입력
I found a similar question:
Converting integers to UTF-8 (Korean)
But I can't figure out how you would do this in .net c#
Problem: I have a string from a database - "\354\202\254\354\232\251\354\236\220\354\203\201\354\204\270\354\240\225\353\263\264\354\236\205\353\240\245"
That should translate to - 사용자상세정보입력
Any help would be greatly appreciated!
解决方案
There are a number of steps involved in the conversion:
- Extract the individual octal numbers (such as
354
) from the source string. - Convert each octal string representation to its decimal equivalent as a byte.
- Decode the byte sequence as UTF-8.
Here's a sample implementation:
string source = @"\354\202\254\354\232\251\354\236\220\354\203\201\354\204" +
@"\270\354\240\225\353\263\264\354\236\205\353\240\245";
byte[] bytes = source.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => (byte)Convert.ToInt32(s, 8))
.ToArray();
string result = Encoding.UTF8.GetString(bytes); // "사용자상세정보입력"
这篇关于我有一串八进制转义,我需要转换为韩文文本 - 不知道如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文