Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 字符串中包含格式不正确的字节数组_C#_String_Bytecode - Fatal编程技术网

C# 字符串中包含格式不正确的字节数组

C# 字符串中包含格式不正确的字节数组,c#,string,bytecode,C#,String,Bytecode,我有一个关于以下问题的问题: // input-String (including four bytes) : d131dd02... // transform Bytes-String in String (this Works!) manually: String message = ((char)0xd1).ToString() + ((char)0x31).ToString() + ((char)0xdd).ToString() + ((char)0x02).ToString()+ ..

我有一个关于以下问题的问题:

// input-String (including four bytes) : d131dd02...
// transform Bytes-String in String (this Works!) manually:
String message = ((char)0xd1).ToString() + ((char)0x31).ToString() + ((char)0xdd).ToString() + ((char)0x02).ToString()+ ....
我想写一个函数,它可以自动将上面给定的输入字符串转换为正确的格式。 我开始写一些代码,但不起作用,因为我不知道该怎么做

if(checkBox1.Checked== true)
{
   String message = null;
   char[] bufferArray = textBox1.Text.ToArray();
   MessageBox.Show(bufferArray.Length.ToString());
   for (int i = 0; i < textBox1.TextLength / 2; i+=2)
   {
      String buffer=("0" + "x" + bufferArray[i] + bufferArray[i+1]);
      message += ((char)buffer.ToString();
   }
   richTextBox1.Text = getMd5Hash(message);
   richTextBox2.Text = MD5HashBerechnen(message).ToLower();
}
if(checkBox1.Checked==true)
{
字符串消息=null;
char[]bufferArray=textBox1.Text.ToArray();
Show(bufferArray.Length.ToString());
对于(int i=0;i
有什么想法吗?

看看这门课


我认为您应该去掉“/2”。

它不起作用的原因是,在第一种情况下,您将数字转换为字符,在第二种情况下,您将字符串转换为字符


0xd1
“0xd1”

不同,您得到的输出是什么?即:“消息”是什么当代码完成时包含?如果同时给出预期的输入和输出以及实际得到的输出,则正确回答此问题会容易得多。输入例如:d1作为字符串;预期的输出:字符串消息=((char)0xd1).ToString;不幸的是,我目前没有计算机为您提供更多数据。我想将任何包含文本格式字节的字符串转换为普通字符串,格式为上面代码-->((char)0xd1)。ToString()ASCII不处理一些示例字节,但处理其他编码(如windows ansi 1252)是的。@Jimmy:没错,我只是用它作为例子,以及为什么我链接到编码类。那么我如何将输入字符串转换成数字,以得到相同的结果呢?你可以使用。
Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(bufferArray));