public static int getCharCode(String s)
{
int value = 0;
if (s == null && s.equals("")) // 改成 s == null || s.equals("")
{
value = -1;
}
else
{
byte[] b = s.getBytes();
for (int i = 0; i < b.length && i <= 2; i++) {
value = value * 100 + b[i];
}
}
return value;
}
{
int value = 0;
if (s == null && s.equals("")) // 改成 s == null || s.equals("")
{
value = -1;
}
else
{
byte[] b = s.getBytes();
for (int i = 0; i < b.length && i <= 2; i++) {
value = value * 100 + b[i];
}
}
return value;
}
如果你不是一定要通过byte来获得的话
那么可以用直接转换的方式,比如取出
String里面的每一个char
然后就直接转换成int,打印出来
就是你要的数字了,看看下面的例子public class CharTest
{
public static void main(String[] args)
{
char ch = '我';
int i = ch;
Integer ii = new Integer(i);
System.out.println( i );
String st = ii.toHexString(i);
System.out.println(ch + " unicode is: \\u" + st);
//System.out.println("\u5220\u9664");
}
}
谢谢XKP(低等下人) 的指教。