%e6%a1%8c%e9%9d%a2 如何转换成汉字。

x____ 2008-10-17 12:04:05
%e6%a1%8c%e9%9d%a2 如何转换成汉字。
...全文
4138 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wenwz 2009-05-21
  • 打赏
  • 举报
回复
顶,学习了
pauliuyou 2008-10-17
  • 打赏
  • 举报
回复


public class StringCoder
{
static char[] hexCharArray = {'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};

public String transform(String src)
{
src = "%e6%a1%8c%e9%9d%a2";
String [] unitArray = src.toUpperCase().split("%");

char [] chars = new char[(unitArray.length - 1) / 2];

int leng = 0;
for (int i = 1; i < unitArray.length; i += 2)
{
byte b1 = hexStringToByte(unitArray[i]);
byte b2 = hexStringToByte(unitArray[i + 1]);
chars[leng++] = (char)((b1 << 8) | (b2 & 0xff));
}
String dest = new String(chars);
return dest;
}

public byte hexStringToByte(String hexStr)
{
System.out.println(hexStr);
int data = 0;
char high = hexStr.charAt(0);
char low = hexStr.charAt(1);

int index = -1;
for (int i = 0; i < hexCharArray.length; i++)
{
if (hexCharArray[i] == high)
{
index = i;
break;
}
}
data += index * 16;
index = -1;
for (int i = 0; i < hexCharArray.length; i++)
{
if (hexCharArray[i] == low)
{
index = i;
break;
}
}
data += index;
return (byte)data;
}
public static void main(String [] args) throws Exception
{
String rs = new StringCoder().transform(null);
System.out.println(rs);
}
}


x____ 2008-10-17
  • 打赏
  • 举报
回复
晕。我不是在html中使用的。包括jsp。压根和网页什么的一点关系也没有。
justinavril 2008-10-17
  • 打赏
  • 举报
回复
放到HTML中 呵呵
pauliuyou 2008-10-17
  • 打赏
  • 举报
回复
UTF8解码终极版本.


public static String decodeUTF8(String src)
{
src = "%e6%a1%8c%e9%9d%a2";
String [] unitArray = src.split("%");
char [] chars = new char[unitArray.length];
int leng = 0;
for (int i = 1; i < unitArray.length;)
{
int data = 0;
byte [] bytes = new byte[5];
bytes[0] = hexStringToByte(unitArray[i]);
int byteNum = getLeftCountOf1InByte(bytes[0]);

for (int j = 1; j < byteNum; j++)
{
bytes[j] = (byte)(hexStringToByte(unitArray[i + j]) & 0x3F);
}
bytes[0] = maskFirstByte(bytes[0]);
int byteCount = 0;
for (int j = byteNum - 1; j >= 0; j--)
{
data |= bytes[j] << (6 * byteCount);
byteCount++;
}
chars[leng++] = (char)data;
i += byteNum;
}
return new String(chars,0,leng);
}

public static byte hexStringToByte(String hexStr)
{
hexStr = hexStr.toUpperCase();
char high = hexStr.charAt(0);
char low = hexStr.charAt(1);

int highVal = 0;
if (high >= '0' && high <= '9')
{
highVal = high - '0';
}
else
{
highVal = 10 + (high - 'A');
}
int lowVal = 0;
if (low >= '0' && low <= '9')
{
lowVal = low - '0';
}
else
{
lowVal = 10 + (low - 'A');
}
return (byte)((highVal << 4) | lowVal);
}

public static int getLeftCountOf1InByte(byte b)
{
int count = 0;
int mask = 1 << 7;
for (int i = 0; i < 8; i++)
{
if ((b & mask) == 0)
{
break;
}
else
{
count++;
mask >>= 1;
}
}
return count;
}

private static byte maskFirstByte(byte b)
{
int mask = 1 << 7;
for (int i = 0; i < 8; i++)
{
if ((b & mask) == 0)
{
break;
}
else
{
b &= ~mask;
mask >>= 1;
}
}
return (byte)b;
}
public static void main(String [] args) throws Exception
{

String rs = new StringCoder().decodeUTF8(null);
System.out.println(rs);
}
qiandongbo 2008-10-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sunyujia 的回复:]
楼上的不错
我一直用这个,原来是桌面啊
java.net.URLDecoder.decode("%e6%a1%8c%e9%9d%a2", "UTF-8")
[/Quote]
顶~
x____ 2008-10-17
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 sunyujia 的回复:]
楼上的不错
我一直用这个,原来是桌面啊
java.net.URLDecoder.decode("%e6%a1%8c%e9%9d%a2", "UTF-8")
[/Quote]
谢谢哈。。
x____ 2008-10-17
  • 打赏
  • 举报
回复
楼上的老兄。。 你的心情是好的。。 但是结果因该是 “桌面” 而不是 “賩鶢”
希望你能针对正确的答案代码修改下。谢谢哈。
x____ 2008-10-17
  • 打赏
  • 举报
回复
楼上的老兄。。 你的心情是好的。。 但是结果因该是 “桌面” 而不是 “賩鶢”
希望你能针对正确的答案代码修改下。谢谢哈。
sunyujia 2008-10-17
  • 打赏
  • 举报
回复
楼上的不错
我一直用这个,原来是桌面啊
java.net.URLDecoder.decode("%e6%a1%8c%e9%9d%a2", "UTF-8")
matlab在一个坐标系内让二维图片堆叠形成三维空间的表示 二维数据或者图片堆叠在三维空间的表示,图片堆叠方便查看 类似origin里面的瀑布图的方法,只是这是在matlab里面实现。 matlab多张图片同时在三维空间中显示,沿着某一个坐标轴 matlab在一个坐标系画不同三维图综合整理,包含了几种画这种堆叠图的介绍的资源,也属于综合整理,感谢各位原作者的贡献。 为了挣点小积分实属不易,望理解,大家可以到TB花一毛五就能帮下载,感谢支持。 码字不易,感谢支持。 也可以去知乎或者CSDN看我写的介绍,链接如下: 知乎:https://zhuanlan.zhihu.com/p/438782250 csdn:https://blog.csdn.net/wmying033/article/details/121625608?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164134593916780274112816%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=164134593916780274112816&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-121625608.pc_search_result_cache&utm_term=matlab%E5%9C%A8%E4%B8%80%E4%B8%AA%E5%9D%90%E6%A0%87%E7%B3%BB%E5%86%85%E8%AE%A9%E4%BA%8C%E7%BB%B4%E5%9B%BE%E7%89%87%E5%A0%86%E5%8F%A0%E5%BD%A2%E6%88%90%E4%B8%89%E7%BB%B4%E7%A9%BA%E9%97%B4%E7%9A%84%E8%A1%A8%E7%A4%BA&spm=1018.2226.3001.4187

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧