问题
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:
- 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); // "사용자상세정보입력"
来源:https://stackoverflow.com/questions/24273673/i-have-a-string-of-octal-escapes-that-i-need-to-convert-to-korean-text-not-sur