将字符串转化为字节流#region 将字符串转化为字节流
/**//// <summary>
/// 将字符串转化为字节流
/// </summary>
/// <param name="_Source">字串</param>
/// <returns>字节流</returns>
public static byte[] String2Bytes(string strSource)
{
System.IO.MemoryStream memoryStream=new System.IO.MemoryStream();
System.IO.BinaryWriter binaryWriter=new System.IO.BinaryWriter(memoryStream);
binaryWriter.Write( strSource );
byte[] buffer=memoryStream.GetBuffer();
return buffer;
}
#endregion
将字节流转化为字符串#region 将字节流转化为字符串
/**//// <summary>
/// 将字节流转化为字符串
/// </summary>
/// <param name="bytData">字节流</param>
/// <returns>字串</returns>
public static string Bytes2String(byte[] bytData)
{
//字节流->字符串
System.IO.MemoryStream memoryStream2 = new System.IO.MemoryStream(bytData);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(memoryStream2);
string s2=binaryReader.ReadString();
return s2;
}
#endregion
/**//// <summary>
/// 将字符串转化为字节流
/// </summary>
/// <param name="_Source">字串</param>
/// <returns>字节流</returns>
public static byte[] String2Bytes(string strSource)
{
System.IO.MemoryStream memoryStream=new System.IO.MemoryStream();
System.IO.BinaryWriter binaryWriter=new System.IO.BinaryWriter(memoryStream);
binaryWriter.Write( strSource );
byte[] buffer=memoryStream.GetBuffer();
return buffer;
}
#endregion
将字节流转化为字符串#region 将字节流转化为字符串
/**//// <summary>
/// 将字节流转化为字符串
/// </summary>
/// <param name="bytData">字节流</param>
/// <returns>字串</returns>
public static string Bytes2String(byte[] bytData)
{
//字节流->字符串
System.IO.MemoryStream memoryStream2 = new System.IO.MemoryStream(bytData);
System.IO.BinaryReader binaryReader = new System.IO.BinaryReader(memoryStream2);
string s2=binaryReader.ReadString();
return s2;
}
#endregion