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 to string
Page Index Toggle Pages: 1
convert int to string (Read 1305 times)
convert int to string
Mar 24th, 2007, 2:08pm
 
Hi

Sorry this is such an easy one but I can't seem to get a conversion from int to string to work

int n = 4;
String s = toString(n);
println(s);

is it toString() or new String(); or has it changed like toInt() to parseInt() and now parseString()??

thanks in advance
gar
Re: convert int to string
Reply #1 - Mar 24th, 2007, 2:26pm
 
int n=4;
String s=""+n;
Re: convert int to string
Reply #2 - Mar 24th, 2007, 2:55pm
 
Thanks, wouldn't have thought that worked but it seems to accept it.

a+
gar
Re: convert int to string
Reply #3 - Mar 24th, 2007, 3:55pm
 
String.valueOf(int i) is slightly more efficient, if less compact. (No need to create an empty string, then prepend it.)
Re: convert int to string
Reply #4 - Mar 24th, 2007, 9:45pm
 
str() is what you're looking for:
http://processing.org/reference/str_.html

(internally it's String.valueOf(blah), without the goofy syntax)
Page Index Toggle Pages: 1