/// <summary>
/// 将字符串转换为字节
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static byte[] StrToBytes(string str)
{
MemoryStream ms = new MemoryStream();
StreamWriter outerstr = new StreamWriter(ms, System.Text.Encoding.GetEncoding("GB2312")); outerstr.Write(str);
outerstr.Flush();
ms.Position = 0;
byte[] bts = new byte[ms.Length]; ms.Read(bts, 0, bts.Length); outerstr.Close();
ms.Close(); return bts;
}
/// 将字符串转换为字节
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static byte[] StrToBytes(string str)
{
MemoryStream ms = new MemoryStream();
StreamWriter outerstr = new StreamWriter(ms, System.Text.Encoding.GetEncoding("GB2312")); outerstr.Write(str);
outerstr.Flush();
ms.Position = 0;
byte[] bts = new byte[ms.Length]; ms.Read(bts, 0, bts.Length); outerstr.Close();
ms.Close(); return bts;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货