开发者

String which contains Byte Array in incorrect form into String

开发者 https://www.devze.com 2023-02-09 06:35 出处:网络
I\'ve a question concerning the following problem: // input-String (including four bytes) : d131dd02...

I've a question concerning the following problem:

// 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()+ ....

I want to write a function which transforms me the above given Input St开发者_Python百科ring in the correct format automatically. I started to write some code but it doesn't work because I have no idea how i've to do it.

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();
}

Any idea?


Look at the Encoding class.

Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(bufferArray));


I think you should just get rid of the " / 2".


The reason it is not working is because in the first case you are casting a number to char, in the second you are casting a string to a char.

0xd1 is not the same as "0xd1"

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号