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)
   Converting a String into an int
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Converting a String into an int  (Read 370 times)
lucidmedia


Converting a String into an int
« on: May 26th, 2004, 5:01am »

Hi All,
 
I am new to programming, so I apologise if this subject is a simple one. I was unable to find an example of this in the documentation and discussion boards.
 
I am building a very basic visualization tool and am looking to transform numbers read in from a text file -- as strings via loadStrings() --  into integers. Seems that most of the data conversion methods -- like int() -- only work with primitive data types. How is this transforation usually performed?
 
Also, any good suggestions on where I can find more (basic) information about parsing and manipulating content read in from external files?
 
thanks!
 
B
 
 
mflux

fluxhavoc WWW
Re: Converting a String into an int
« Reply #1 on: May 26th, 2004, 9:35am »

coverting an entire string into an integer doesn't make a whole lot of sense.
 
I think what you're looking for is splitting the string into an array of characters, then converting them all into integers while you're at it?
 
check out splitstrings()
 
lucidmedia


Re: Converting a String into an int
« Reply #2 on: May 26th, 2004, 6:20pm »

Thanks for your help... greatly appreciated... I am not looking to convert an entire string of text, just numbers read in from a text list.
 
splitStrings() will be very helpful in chunking down my fields, but I am still looking for a way to turn these characters into integers.  
 
I have currently solved this by using Float.valueOf() then using int() for conversion. Is there a better way to do this?
 
thanks
 
TomC

WWW
Re: Converting a String into an int
« Reply #3 on: May 26th, 2004, 6:27pm »

mflux's answer is kind of right, but a little wobbly
 
Take a look at splitInts() which does what you're asking...
 
http://processing.org/reference/splitInts_.html
 
 
(Oh, and the pure Java way would use Integer.parseInt() instead).
« Last Edit: May 26th, 2004, 6:32pm by TomC »  
kevinP

Email
Re: Converting a String into an int
« Reply #4 on: May 26th, 2004, 9:09pm »

Hi Tom,
 
Thanks for your (and others') always helpful replies. I think that the added reference to an equivalent or similar java method/class (as you did here) is especially helpful.
« Last Edit: May 26th, 2004, 9:10pm by kevinP »  

Kevin Pfeiffer
Pages: 1 

« Previous topic | Next topic »