.NET C# 特殊字符
我有一个 C# 应用程序,我试图在其中创建一个包含结尾 \0 的字符串。 我没能做到这一点。
我做了:
string msg = "GGGG..8";
byte []b = System.Text.encoding.GetBytes(msg);
但在 b 中,其中“..”表示的是 46 而不是 00。 我想要 \0\0
而不是 ..
最终目标是让字符串包含消息。
I have a C# application in which I am trying to make a string that will contain near the end \0.
I didn't manage to do that.
I did:
string msg = "GGGG..8";
byte []b = System.Text.encoding.GetBytes(msg);
but in b where ".." are the representation is 46 and not 00.
I want instead of ..
to have \0\0
The final goal was to have the string contain the message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建适当的字符串很容易:
不清楚您在第二行中尝试使用什么编码,但我希望大多数单字节编码将 '\0' 编码为 0 字节。
如果您想获取原本包含句点的消息并将其转换为“\0”字符,这也很简单:
Creating an appropriate string is easy:
It's not clear what encoding you were trying to use in the second line, but I'd expect most single-byte encodings to encode that '\0' as a 0 byte.
If you want to take a message which originally includes periods and convert them to '\0' characters, that's easy too:
这应该有效:
如果运气不好,请尝试以下操作:
This should work:
If no luck try this: