用好这些就够了吧
[C#] 纯文本查看 复制代码 #region Encoding
/// <summary>
/// 将字节数组转为字符串
/// </summary>
/// <param name="b">字节数组</param>
/// <param name="e">编码,默认为Default</param>
/// <returns>字符串</returns>
public static string ByteToString(byte[] b, Encoding e = null)
{
return EncodingHelper.ByteToString(b, e);
}
/// <summary>
/// 将字符串转为字节数组
/// </summary>
/// <param name="s">字符串</param>
/// <param name="e">编码,默认为Default</param>
/// <returns>字节数组</returns>
public static byte[] StringToByte(string s, Encoding e = null)
{
return EncodingHelper.StringToByte(s, e);
}
#endregion
#region Base64
/// <summary>
/// 将Base64编码解析成字符串
/// </summary>
/// <param name="strbase">要解码的string字符</param>
/// <param name="encoding">字符编码方案</param>
/// <returns>字符串</returns>
public static string Base64ToString(string strbase, Encoding encoding)
{
return Base64Helper.Base64ToString(strbase, encoding);
}
/// <summary>
/// 将字节数组为Base64编码
/// </summary>
/// <param name="bytebase">要编码的byte[]</param>
/// <returns>base字符串</returns>
public static string ByteToBase64(byte[] bytebase)
{
return Base64Helper.StringToBase64(bytebase);
}
/// <summary>
/// 将字符串转为Base64编码
/// </summary>
/// <param name="str">要编码的string字符</param>
/// <param name="encoding">字符编码方案</param>
/// <returns>base字符串</returns>
public static string StringToBase64(string str, Encoding encoding)
{
return Base64Helper.StringToBase64(str, encoding);
}
#endregion
编辑转换就一句话
string result = Encoding.Default.GetString(你要转的字符串);
感觉意义不大,最主要是当页面内容获取之后你再转换是无效的,比如你使用Utf-8提取的内容,直接转为gbk基本不生效,只有从流中转才有意义。
但既然是从流转了,那直接在获取时传入即可。
|