Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 sorry but...
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lionheart




PostPosted: 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!
Sponsor
Sponsor
Sponsor
sponsor
Andy




PostPosted: Thu Apr 28, 2005 7:23 pm   Post subject: (No subject)

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




PostPosted: 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
wtd




PostPosted: Thu Apr 28, 2005 7:27 pm   Post subject: (No subject)

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




PostPosted: 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
Hikaru79




PostPosted: 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]);
}
rizzix




PostPosted: 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);
alex69s




PostPosted: 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));
        }
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: