I have a string of octal escapes that I need to convert to Korean text - not sure how

孤街醉人 提交于 2020-01-06 15:25:14

问题


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!


回答1:


There are a number of steps involved in the conversion:

  1. Extract the individual octal numbers (such as 354) from the source string.
  2. Convert each octal string representation to its decimal equivalent as a byte.
  3. 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);   // "사용자상세정보입력"


来源:https://stackoverflow.com/questions/24273673/i-have-a-string-of-octal-escapes-that-i-need-to-convert-to-korean-text-not-sur

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!