代码之家  ›  专栏  ›  技术社区  ›  Louis Rhys

如何在C中把字符串转换成字节[]#

  •  8
  • Louis Rhys  · 技术社区  · 15 年前

    如何从C#中的字符串中获取字节数组?我想传一根线给你 this method

    4 回复  |  直到 15 年前
        1
  •  7
  •   Noffls    15 年前
    Encoding.UTF8.GetBytes("abcd");
    
        2
  •  2
  •   Thariama    15 年前

    尝试

    public static byte[] StrToByteArray(string str)
    {
        System.Text.UTF8Encoding  encoding=new System.Text.UTF8Encoding();
        return encoding.GetBytes(str);
    }
    
        3
  •  1
  •   Sachin Shanbhag    15 年前
        4
  •  0
  •   Itay Karo    15 年前

    Encoding.GetBytes