Dear all,
I have a program.
public class StringTest {
public static void main(String[] args)
{
String test = "a1b2c3";
String[] tokens = test.split("\\d");
for(String s:tokens) System.out.print(s+ " ");
}
}
Output :
E:\%26gt;java StringTest
a b c
--------------------------------------...
I want output 1 2 3
Can you explain the split method ih this example ?
String[] tokens = test.split("\\s");
Reply:try split("[0-9]") instead of split("\\d")
Reply:Instead of String[] tokens = test.split("\\d"); you will have to do String[] tokens = test.split("\\D");, and it will work!
tarot cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment