hi!
how do I convert a string that I get from command lite to char array?
I have args[0]="this is test"
and I want to by able to print
"
t
h
i
... and so on, but Iam having hard time to converting the sting to chars

Signature
thanx in advance
______________________________
javaboi - 07 Apr 2005 07:51 GMT
> hi!
>
[quoted text clipped - 6 lines]
> i
> ... and so on, but Iam having hard time to converting the sting to chars
javaboi - 07 Apr 2005 07:53 GMT
Here's one way:
***********
String s1 ="this is one";
char[] mychars = s1.toCharArray();
for (int i = 0; i < mychars.length; i++) {
System.out.println("The current character is: " + mychars[i]);
}
Wannabee - 07 Apr 2005 09:05 GMT
> hi!
>
[quoted text clipped - 6 lines]
> i
> ... and so on, but Iam having hard time to converting the sting to chars
Maybe you mean this? (untested)
public class Grazy {
public static void main(String[] args) {
if (args == null || args.length == 0) {
System.out.println("Give a command line parameter!");
return;
}
System.out.println("\"");
// The first " is not part of the String ;-)
char[] chars = args[0].toCharArray();
for (int i = 0; i < chars.length; i++) {
System.out.println(chars[i]);
}
// Maybe you want it also to end with a "
System.out.println("\"");
}
}