V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
zxCoder
V2EX  ›  问与答

c#的 System.Text.Encoding.UTF8.GetString

  •  
  •   zxCoder · Dec 11, 2020 · 598 views
    This topic created in 1966 days ago, the information mentioned may be changed or developed.

    有没有可能对于两个不同的 byte 数组,解析出相同的字符串呢?

    刚才遇到一个情况,接收到的字符数组本来应该去掉前 5 个头部字节,再转成 string,但是发现直接转 string 得到的字符串居然看起来是一样的,但是==比较是不一样的,长度也不一样

    // res 是 byte[1024] 其中前 5 个字符是 header,从 res[5]到 res[17]等同于 rec.data
    string a = System.Text.Encoding.UTF8.GetString(res);
    // rec.data 是 byte[13]
    string b = System.Text.Encoding.UTF8.GetString(rec.data);
    // 1024 13
    Console.WriteLine(a.Length+" "+b.Length);
    

    不太理解这是为什么这是为什么呢

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2647 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 03:14 · PVG 11:14 · LAX 20:14 · JFK 23:14
    ♥ Do have faith in what you're doing.