开发者

UTF8.GetString strips special character (0xd 0xa)

I am using UTF8.GetString to read context from inbound stream, store it to database varchar typed column, but it seems I am missing the开发者_运维问答 special character 0xd 0xa. How can I correct this?

Thanks advance for the help!

edit: inbound stream is represented in bytes


That's not a single character - that's two characters, "carriage return" U+000D and "line feed" U+000A... and the UTF-8 decoder can certainly handle them. Sample code:

using System;
using System.Text;

class Test
{
    static void Main()
    {
        byte[] bytes = { 0x41, 0xd, 0xa, 0x42 };
        string text = Encoding.UTF8.GetString(bytes);
        Console.WriteLine(text == "A\r\nB");
    }
}

Are you sure your database isn't stripping the characters? Or if you've got XML input, perhaps that's stripping it, believing it to be ignorable whitespace?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜