asp..net 字符串转换问题
在一个asp的网页源码里面看到了这样一行代码TutPic="/Images/Surname/"& (hex(asc(fname))) &".gif"
fname是一个字符串
然后网页上显示的效果就是Images/Surname/D5D4.gif
这个转换如何用asp.net来实现?
追问:这个是VB的一个函数 hex(asc(李)) 转换后的结果是COEE (那个fname是个参数“李”)
如果我要用asp.net来实现同样的转换的话 应该怎么写?
在一个asp的网页源码里面看到了这样一行代码TutPic="/Images/Surname/"& (hex(asc(fname))) &".gif"
fname是一个字符串
然后网页上显示的效果就是Images/Surname/D5D4.gif
这个转换如何用asp.net来实现?
追问:这个是VB的一个函数 hex(asc(李)) 转换后的结果是COEE (那个fname是个参数“李”)
如果我要用asp.net来实现同样的转换的话 应该怎么写?
答案: 整理了两个函数//'汉字转16进制,source为传过来的汉字字符串
public string ConvertStringToHex(string source)
{
byte[] bytes = System.Text.Encoding.GetEncoding("gb2312").GetBytes(source);
string str = "";
for (int i = 0; i < bytes.Length; i++)
{
str += string.Format("{0:X}", bytes[i]);
}
return str;
}
//'16进制转汉字,source为传过来的16进制的汉字字符串
public string ConvertHexToString(string source)
{
byte[] oribyte = new byte[source.Length / 2];
for (int i = 0; i < source.Length; i += 2)
{
string str = Convert.ToInt32(source.Substring(i, 2), 16).ToString();
oribyte[i / 2] = Convert.ToByte(source.Substring(i, 2), 16);
}
return System.Text.Encoding.Default.GetString(oribyte);
}这不是转换,这是传参数传过来的,那个fname是个参数值
上一个:asp.net读取sql数据库
下一个:asp.net问题 很急