%e6%a1%8c%e9%9d%a2 如何转换成汉字。 %e6%a1%8c%e9%9d%a2 如何转换成汉字。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 晕。我不是在html中使用的。包括jsp。压根和网页什么的一点关系也没有。 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); }} 楼上的不错我一直用这个,原来是桌面啊java.net.URLDecoder.decode("%e6%a1%8c%e9%9d%a2", "UTF-8") 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); } javaSE通讯录 如何用事件来控制方法的执行! 请教用流读txt文档问题!!! 请大家帮我,统计日期天数的问题 菜鸟高分求教: 如何取得URL地址? some questions(continue) intValue()方法调用问题 问一个原始问题: 我装好j2se后 ,classpth, path 都设好了但还是出错为什么? scjp 真题一个??? 请问什么是rmi-iiop? java中把数据库的内容显示在TextFiled中,并实现修改功能? JAVA面向对象该怎么学?
{
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);
}
}
我一直用这个,原来是桌面啊
java.net.URLDecoder.decode("%e6%a1%8c%e9%9d%a2", "UTF-8")
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);
}