简体   繁体   English

.NET C#特殊字符

[英].NET C# special character

I have a C# application in which I am trying to make a string that will contain near the end \\0. 我有一个C#应用程序,我试图在其中创建一个字符串,该字符串将包含\\ 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 但在b中,“ ..”表示的是46而不是00。我要代替..来具有\\ 0 \\ 0
The final goal was to have the string contain the message. 最终目标是使字符串包含消息。

Creating an appropriate string is easy: 创建合适的字符串很容易:

string msg = "GGGG\0\08";

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. 目前尚不清楚您在第二行中尝试使用哪种编码,但是我希望大多数单字节编码会将“ \\ 0”编码为0字节。

If you want to take a message which originally includes periods and convert them to '\\0' characters, that's easy too: 如果要接收最初包含句点的消息并将其转换为'\\ 0'字符,这也很容易:

string msg = "GGGG..8";
string replaced = msg.Replace('.', '\0');

This should work: 这应该工作:

string msg = "GGGG..8\0";

If no luck try this: 如果没有运气,请尝试以下操作:

string msg = "GGGG..8" + '\0';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM