Topic: 字符串的问题

  Print this page

1.字符串的问题 Copy to clipboard
Posted by: orangeyxj
Posted on: 2005-03-30 17:47

我在论坛看到字符串转成整数有几种方法:
). int i = Integer.parseInt([String]); 或
i = Integer.parseInt([String],[int radix]);
2). int i = Integer.valueOf(my_str).intValue();
但是这些方法里的String参数必须是数字如“12345678”,才能正常转换如果是“abc”则会抛出异常,这是为什么?

另外,字符串"abc"通过getBytes() 可以取得 a是97,b是98,c是99,
如果我想把三个整数 97 98 99转成“abc”有该怎么转呢?

先谢谢了

2.Re:字符串的问题 [Re: orangeyxj] Copy to clipboard
Posted by: why
Posted on: 2005-03-30 21:38

check the Java API
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Integer.html#parseInt(java.lang.String, int)
public static int parseInt(String s,
int radix)
throws NumberFormatException

Integer.parseInt("abc",16) should be fine since "abc" is a valid hex number

note that Integer.parseInt(String) == Integer.parseInt(String,10)


>> 如果我想把三个整数 97 98 99转成“abc”有该怎么转呢?
put them into an byte array, say bytes and
new String(bytes)

3.Re:字符串的问题 [Re: orangeyxj] Copy to clipboard
Posted by: orangeyxj
Posted on: 2005-03-31 11:54

谢谢总版主

4.Re:字符串的问题 [Re: orangeyxj] Copy to clipboard
Posted by: wddodo
Posted on: 2005-04-02 14:41

谢谢版主,又学到些东西

5.Re:字符串的问题 [Re: orangeyxj] Copy to clipboard
Posted by: undefined
Posted on: 2005-04-14 10:49

总斑竹是老外??怎么不说中国话?


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923