[C#] Convert byte[] to string (binary byte array to string)
Tag:[C#] [byte] [Conversion]
You may want the string to convert from byte array(byte[]). In c#, strings are defined as unicode. Therefore, you must convert byte[] array to copy into a string, as well as including the encoding process. And System.Text.Encoding class is provided in c# using this class can convert byte[] and string types.
When converting string from the byte[] type uses GetString() method.

private void button1_Click(object sender, EventArgs e)
  byte[] data;
  data = GetData(); //Get something byte[] data

  //data is encoded with ASCII
  string text = System.Text.Encoding.ASCII.GetString(data);
  //data is encoded with Shift-JIS
  //string text = System.Text.Encoding.GetEncoding("shift_jis").GetString(data);

  //data is encoded with EUC
  //string text = System.Text.Encoding.GetEncoding("euc-jp").GetString(data);

  //data is encoded with unicode
  //string text = System.Text.Encoding.Unicode.GetString(data);

  //data is encoded with utf-8
  //string text = System.Text.Encoding.UTF8.GetString(data);

Register date :2011-10-16    Last update :2017-01-17
Tag:[C#] [byte] [Conversion]
プライバシー    iPentecについて
iPentec all rights reserverd. (ISDC)