最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 10进制字符串转换为十六进制字符串
时间:2011-01-19 编辑:简简单单 来源:一聚教程网
asp教程.net 10进制字符串转换为十六进制字符串
public string strtohex(string mstr) //返回处理后的十六进制字符串
{
return bitconverter.tostring(
asciiencoding.default.getbytes(mstr)).replace("-", " ");
} /* strtohex */
16进制字符串转换为10进制字符串
public string hextostr(string mhex) // 返回十六进制代表的字符串
{
mhex = mhex.replace(" ", "");
if (mhex.length <= 0) return "";
byte[] vbytes = new byte[mhex.length / 2];
for (int i = 0; i < mhex.length; i += 2)
if (!byte.tryparse(mhex.substring(i, 2), numberstyles.hexnumber, null, out vbytes[i / 2]))
vbytes[i / 2] = 0;
return asciiencoding.default.getstring(vbytes);
} /* hextostr */
字符串转换为宽字符
public static string stringtowchar(string s)
{
stringbuilder outs = new stringbuilder();
foreach (char item in s)
{
if (isencoding(item))//判断是否编码
{
outs.append(string.format("u{0:x4}", (int)item));
}
else//不是中文
{
outs.append(item);
}
}
return outs.tostring();
}
private static bool isencoding(char cha)
{
string nonencodingchats = "abcdefghijklmnopqrstuvwxyz0123456789`!@#$%^&*()_+|-=,./;'[]{}:<>?";
return nonencodingchats.indexof(cha) == -1;
}
-
上一个: 几个Asp.Net上传文件的控件收集
-
下一个: asp.net超大文件上传方法
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10