QiFeng.ZWY.Utility/DataHelper/HexCodeHelper.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QiFeng.LMSD.Utility
{
public class HexCodeHelper
{
/// <summary>
/// 从汉字转换到16进制
/// </summary>
/// <param name="s"></param>
/// <param name="charset">编码,如"utf-8","gb2312"</param>
/// <param name="fenge">是否每字符用逗号分隔</param>
/// <returns></returns>
public static string ToHex(string s, string charset, bool isSplit, string splitChar)
{
if ((s.Length%2) != 0)
{
s += " "; //空格
}
System.Text.Encoding chs = System.Text.Encoding.GetEncoding(charset);
byte[] bytes = chs.GetBytes(s);
string str = string.Empty;
for (int i = 0; i < bytes.Length; i++)
{
str += string.Format("{0:X}", bytes[i]);
if (isSplit && (i != bytes.Length - 1))
{
str += string.Format("{0}", splitChar);
}
}
return str.ToLower();
}
/// <summary>
/// 从16进制转换成汉字
/// </summary>
/// <param name="hex"></param>
/// <param name="charset">编码,如"utf-8","gb2312"</param>
/// <returns></returns>
public static string UnHex(string hex, string charset)
{
if (hex == null)
throw new ArgumentNullException("hex");
hex = hex.Replace(",", "");
hex = hex.Replace("\n", "");
hex = hex.Replace("\\", "");
hex = hex.Replace(" ", "");
if (hex.Length%2 != 0)
{
hex += "20"; //空格
//throw new ArgumentException("hex is not a valid number!", "hex");
}
后面还有 54 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。