Computer Science Canada

sorry but...

Author:  lionheart [ Thu Apr 28, 2005 7:22 pm ]
Post subject:  sorry but...

is there a way to split a string into many chars..
like
John Doe
into
variable1 = 'j'
variable1 = 'o'
variable1 = 'h'
variable1 = 'n'

variable1 = 'D'
variable1 = 'o'
variable1 = 'e'
arg im not very gud at java..
i liked turing better lol
twas easier!

Author:  Andy [ Thu Apr 28, 2005 7:23 pm ]
Post subject: 

what type of string are you talking about? character array or java String object?

Author:  lionheart [ Thu Apr 28, 2005 7:24 pm ]
Post subject:  oh...

i mean a character array so that you can put the letters of the string in it..
i am aware of..
split() but doesn't that nly work for seperate words

Author:  wtd [ Thu Apr 28, 2005 7:27 pm ]
Post subject: 

Java:
String s = "Hello";
char[] letters = s.toCharArray();

Author:  lionheart [ Thu Apr 28, 2005 7:33 pm ]
Post subject:  yay it works

ok lol
now how do you call it to output >.<

thanks for helping btw
ahh
stupid me..!
got it

Author:  Hikaru79 [ Thu Apr 28, 2005 8:20 pm ]
Post subject:  Re: yay it works

lionheart wrote:
ok lol
now how do you call it to output >.<

Just go through every element of the array.
Java:

for (int x=0; x<letters.length;x++){
System.out.println(letters[x]);
}

Author:  rizzix [ Fri Apr 29, 2005 3:03 pm ]
Post subject:  Re: oh...

lionheart wrote:
i mean a character array so that you can put the letters of the string in it..
i am aware of..
split() but doesn't that nly work for seperate words


no it dosen't.. it can work on individual characters.. just supply it the "correct" regex for the delimiter.. in the case of separating individual characters.. there is no delimiter so supply an empty String..

code:
String[] split = "John Doe".split("");
        for (String s : split)
            System.out.println(s);

Author:  alex69s [ Thu Jun 02, 2005 10:59 pm ]
Post subject:  or

just do:

code:
        String s = "Hello";
        for (int x = 0 ; x < s.length() ; x++)
        {
            System.out.println (s.charAt (x));
        }


: