Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String spliting
02-06-2008, 02:06 PM
Post: #1
String spliting
I have a string

String str = "1,2,3,4,5";

How can I split the numbers between comma.
Find all posts by this user
Quote this message in a reply
02-06-2008, 02:09 PM
Post: #2
RE: String spliting
You can use StringTokenizer for this purpose.

[java]
String str = "1,2,3,4,5";
StringTokenizer strToken = new StringTokenizer(str, ",");
while (strToken.hasMoreTokens()) {
System.out.println(strToken.nextToken());
}
[/java]
Find all posts by this user
Quote this message in a reply
02-06-2008, 02:11 PM
Post: #3
RE: String spliting
Or use split method of String class.

[java]
String[] splittedString = str.split(",");
[/java]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: