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 › Cannot convert String to String[]
Page Index Toggle Pages: 1
Cannot convert String to String[] (Read 745 times)
Cannot convert String to String[]
Mar 11th, 2010, 12:12pm
 
Hello everyone,

Have a simple one here, had it working last night. Didn't save it and lost power, my dumb mistake. I have had to start from scratch again and keep getting the error above.

I am trying to load a text file and clean it up to remove the whitespace. Not sure why I keep getting the "Cannot convert String to String[]". Obviously not the best coder but I'm getting better. I'm sure it something simple that I am missing.

Thanks to all.

Code:
void setup() {
 String[] lotteryRaw = loadStrings("lottery") ;
 int numLines = lotteryRaw.length;
 println(numLines + " lines of data loaded");
 println("Starting parse...");
 parse(lotteryRaw);
 
}

void parse(String[] lotteryRaw) {
 for (int i = 0; i < lotteryRaw.length; i++) {
   String[] clean = lotteryRaw[i].replaceAll("\\W", "") ;
   println(clean[i]);
 }
}


Re: Cannot convert String to String[]
Reply #1 - Mar 11th, 2010, 12:17pm
 
Well, indeed it is simple: replaceAll returns a string, not an array of strings.
   String clean = lotteryRaw[i].replaceAll("\\w", "") ;
   println(clean);

Oh, and I replaced W with w, unless you want to keep only the whitespace...
Re: Cannot convert String to String[]
Reply #2 - Mar 11th, 2010, 12:20pm
 
Awesome,

Thanks for the help, I knew it was something simple. It's amazing how at 3am the magic just flows, but in the afternoon it's a struggle.

Thanks again.
Page Index Toggle Pages: 1