String转换为Byte Array

// C# to convert a string to a byte array.
public static byte[] StrToByteArray(string str)
{
    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
    return encoding.GetBytes(str);
}

 

Byte Array转换为String

// C# to convert a byte array to a string.
public static byte[] ByteArrayToStr(string str)
{
    byte[] dBytes = { 1, 2, 3 };
    string string1;
    System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
    string1 = enc.GetString(dBytes);
}

 

资料来源:

How do I convert a string to a byte array and vica-versa in VB.NET and C#?

http://www.chilkatsoft.com/faq/dotnetstrtobytes.html

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2021-12-24
  • 2022-01-28
  • 2022-12-23
  • 2021-08-20
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2021-10-18
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2022-02-05
  • 2022-12-23
相关资源
相似解决方案