PDA

View Full Version : แปลง string เป็น integerใน JAVA



ar3s
30-01-2003, 05:12 PM
ใช้คำสั่งอะไรครับ คือมีปัญหาในการเขียนโปรแกรมเพราะถ้า ไม่แปลงค่ามาเป็นตัวเลขจะต้อง check เงื่อนไข if ยาวเลย ช่วยหน่อยนะครับ

[Edited by admin on 01-30-2003 at 10:28 AM GMT]

asylu3
30-01-2003, 05:26 PM
ลองดูโค้ดนี้ดูนะครับ คิดว่าคงพอได้ idea


String strNum = "123";
int intNum = Integer.parseInt(strNum);

ar3s
19-12-2004, 11:02 AM
class Test1 {
public static void main(int args[]){
int n = (args[0]);
System.out.println(n);
}
}

Class Test2 {
public static void main(String args[]){
int n = Integer.parseInt(args[0]);
System.out.println(n)
}
}

labyrinth
22-12-2004, 06:43 PM
กลับกันอะ



String str = Integer.toString(123);

ar3s
28-09-2005, 02:00 AM
class Input{
public String getInput() {
char buf = '

ar3s
21-02-2006, 01:44 AM
ทำไรกันยืดยาวครับแค่แปลงเลขเป็นสตริง

String s = 1 + "";

kingmot
08-11-2006, 09:34 AM
Converting int to string

String myString = Integer.toString(my int value)

or
String str = "" + i


ที่มา : http://www.narisa.com/forums/index.php?showtopic=11724