We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › HELP..breaking down words into single char
Page Index Toggle Pages: 1
HELP..breaking down words into single char (Read 770 times)
HELP..breaking down words into single char
Oct 22nd, 2009, 9:58am
 
hi all,

i m writing a program to break down words to char, for example here is a string array element    

String words[0]="hello";

how can i break down each character and put them into another string array???????          

String break_down[0]="h";
String break_down[1]="e";
String break_down[2]="l";
String break_down[3]="l";
String break_down[4]="o";

by the way, i m not sure i should use string or char array to achieve this....can anybody help me?thank you so much.
Re: HELP..breaking down words into single char
Reply #1 - Oct 22nd, 2009, 10:06am
 
char[] = mystring.toCharArray();
Re: HELP..breaking down words into single char
Reply #2 - Oct 22nd, 2009, 1:22pm
 
BenHem's method is fine, just remember to cast your chars to String.
Alternative:
Code:
String str = "Hello, World!";
String[] strs = str.split("");
println(strs);

but you have to discard the first item.
Re: HELP..breaking down words into single char
Reply #3 - Oct 24th, 2009, 10:04am
 
thank you very much:)
Page Index Toggle Pages: 1