FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   cast splitStrings as int?
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: cast splitStrings as int?  (Read 254 times)
jkeirstead

WWW
cast splitStrings as int?
« on: Apr 17th, 2004, 8:31pm »

Hi,
 
I'm trying to read in data from a file, with each line containing tab-separated integers and strings.  I can get the data in fine and use splitStrings to divide each line into "words" but I can't cast the words as ints - any ideas?  I get an error that says "An expression of type "java/lang" cannot be cast into type "String""
 
Here's a code excerpt.
 
  String words[]=splitStrings(lines[i],'\t');
  println(int(words[j]));
 
Where j is an int < words.length
 
Thanks!
« Last Edit: Apr 17th, 2004, 8:33pm by jkeirstead »  
TomC

WWW
Re: cast splitStrings as int?
« Reply #1 on: Apr 17th, 2004, 8:46pm »

Processing's casts don't work on Strings (though maybe they could/should?)
 
Use splitInts instead...
 
http://processing.org/reference/splitInts_.html
 
Code:

int numbers[]=splitInts(lines[i],'\t');  
println(numbers[j]);

 
Oh, and if you want to get just one int from a String you can use the standard Java class Integer to do it for you.
 
Code:

String numberString = "100";
int number = Integer.parseInt(numberString);
println(number);
« Last Edit: Apr 17th, 2004, 8:47pm by TomC »  
Pages: 1 

« Previous topic | Next topic »