Shamsudeen Akanbi wrote:Hey, what I'm saying is that: I key in a string and I get characters in an array. You see, something like this. Split the word "SAMSON" into individual characters. So in my array I get 'S' 'A' 'M' 'S' 'O' 'N' .
I tried string.split() and the delimiter was a "\\s"
. So what I mean in short is that, instead of spacing SAMSON at the command line,
isn't there any REGULAR EXPRESSION i can use.
Shamsudeen Akanbi wrote:Please I'm trying to split a string into characters to, be stored in an array. But I don't know which delimiter I'm to use. I've been trying including spaces so that \\s splits it, but that's not exactly what I want.
import java.util.*;
class MyClass {
public static void main(String[] args) {
String[] token = args[0].split("\\s");
String a = token[0] + token[1] + token[2];
System.out.print (a);
}
}
Thanks in advance.
Chetan Sarnad wrote:
I guess you are trying to split the command line argument i.e the string at each occurrence of spaces,
So I guess this should be good enough if the string is like "My name is Shamsudeen Akanbi"
Jeff Verdegan wrote:
He's actually stated quite explicitly that that's NOT what he wants.
String [] p=args[0].split("");
Oscar G. Rodriguez wrote:Another one that thinks you have to use toCharArray(), but if you don't want to, you can try with
String [] p=args[0].split("");
You'll obtain the String[], but the first element will be "".
Oscar G. Rodriguez wrote:Well, I don't know if I wrote what I want to said, my English isn't very good.
I think that he ought to use toCharArray(), another one was me because I understood that you said the same.
Sorry for the misunderstanding.