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 › Convert int array to string array
Page Index Toggle Pages: 1
Convert int array to string array (Read 1134 times)
Convert int array to string array
May 2nd, 2010, 9:28am
 
Hi, I'm trying to debug my program which has columns which increase everytime the mouse is pressed in a range of the x-axis.

The program works until this part:

Code:

/* global integers */
int NumCols = 10;
int[] ColHs = new int [NumCols];
...
/* main program etc */
...
void keyPressed() {
int i;
String[] Array_of_String = new String[NumCols];
for (i = 0; i < NumCols; i++) {
Array_of_String[i] = ColHs[i];
}
saveStrings("IP.csv", Array_of_String);
}


I'm getting a "cannot convert int to string" error and i'm not sure why or how to fix this  Sad If anyone could point me in the right direction that'd be great! Cool
Re: Convert int array to string array
Reply #1 - May 2nd, 2010, 9:32am
 
See str().
It even does the loop for you!
Re: Convert int array to string array
Reply #2 - May 2nd, 2010, 10:01am
 
THANKS!!!! Exactly what i was looking for!

What did you mean by "it even does the loop for you"?

my code now:

Code:
/* global integers */
int NumCols = 10;
int[] ColHs = new int [NumCols];
...
/* main program etc */
...
void keyPressed() {
 int i;
 String[] Array_of_String = new String[NumCols];
 for (i = 0; i < NumCols; i++) {
   Array_of_String[i] = str(ColHs[i]);
 }  
/* added str() to ColHs[i]) */

 saveStrings("IP.csv", Array_of_String);
}


How would i be able to replace the "for loop" ?

It works great now, thanks for the pointer Smiley
Re: Convert int array to string array
Reply #3 - May 2nd, 2010, 11:25am
 
str() accepts a int[] as input and can output a String[].
Page Index Toggle Pages: 1