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 › COnverting array of strings to ints.
Pages: 1 2 
COnverting array of strings to ints. (Read 1902 times)
Re: COnverting array of strings to ints.
Reply #15 - Nov 27th, 2009, 4:55am
 
Code:
int[] xPositionArray;
String[] xStringsArray;

void setup(){
 size(200, 200);
 xStringsArray = loadStrings("xPositionsArray26112009.txt");
 println(xStringsArray);
 xPositionArray = new int[xStringsArray.length];
 
 
 for(int i=0; i < xPositionArray.length; i++){
   xPositionArray[i] = int(xStringsArray[i].trim());
 }
 println(xPositionArray);
}

int() doesn't like the leading space in your numbers.
Re: COnverting array of strings to ints.
Reply #16 - Nov 27th, 2009, 6:10am
 
Ah I see, I havent come across trim() before. Thankyou once again, i'm one step closer to a worth-while sketch!  Smiley
Re: COnverting array of strings to ints.
Reply #17 - Nov 27th, 2009, 6:51am
 
i thought the problem is in the file. if you have formating problems like this, sometimes its easy to just open it in notepad for example and replace " " with "" or what ever needs to be removed.
Re: COnverting array of strings to ints.
Reply #18 - Nov 27th, 2009, 7:12am
 
Good tip! - If only i'd know that it was as simple as that!
Pages: 1 2