Help with \0 terminated strings in C#
问题 I'm using a low level native API where I send an unsafe byte buffer pointer to get a c-string value. So it gives me // using byte[255] c_str string s = new string(Encoding.ASCII.GetChars(c_str)); // now s == "heresastring\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0(etc)"; So obviously I'm not doing it right, how I get rid of the excess? 回答1: .NET strings are not null-terminated (as you may have guessed from this). So, you can treat the '\0' as you would treat any normal character. Normal string