digitalmars.D.learn - Integer to String
- tytower <tytower yahoo.com> Jan 30 2008
- Lutger <lutger.blijdestijn gmail.com> Jan 30 2008
- naryl <cy ngs.ru> Jan 30 2008
- bearophile <bearophileHUGS lycos.com> Jan 30 2008
- Lutger <lutger.blijdestijn gmail.com> Jan 30 2008
- Frank Benoit <keinfarbton googlemail.com> Jan 30 2008
- Frank Benoit <keinfarbton googlemail.com> Jan 30 2008
- ty tower <tytower yahoo.com.au> Jan 30 2008
I'm pulling my hair out to simply take a number say 37 and convert it to a string under Tango int x = 37 Char[] y = intToString(x); how the blazes do I make this simple little thing work??
Jan 30 2008
tytower wrote:I'm pulling my hair out to simply take a number say 37 and convert it to a string under Tango int x = 37 Char[] y = intToString(x); how the blazes do I make this simple little thing work??
see http://www.dsource.org/projects/tango/wiki/ChapterConversions#Integer import Integer = tango.text.convert.Integer; ... int x = 37; char[] y = toString(x);
Jan 30 2008
On Wed, 30 Jan 2008 12:47:38 +0300, tytower <tytower yahoo.com> wrote:I'm pulling my hair out to simply take a number say 37 and convert it =
a string under Tango int x =3D 37 Char[] y =3D intToString(x); how the blazes do I make this simple little thing work??
http://www.dsource.org/projects/tango/wiki/ChapterConversions#Conversion= betweentextandnumerictypes For your example: import tango.text.convert.Integer; ... int x =3D 37; char[] y =3D toString(x);
Jan 30 2008
naryl:import tango.text.convert.Integer; int x = 37; char[] y = toString(x);
That sounds too much deep, what about something like: import tango.text; auto s = toString(37); Or: import tango.text; auto s = str(37); Or (no imports, but this requires compiler support): auto s = cast(string)37; Or maybe best of all: auto s = string(37); I think the design of a good simple way of doing things is very important. Bye, bearophile
Jan 30 2008
tytower schrieb:I'm pulling my hair out to simply take a number say 37 and convert it to a string under Tango int x = 37 Char[] y = intToString(x); how the blazes do I make this simple little thing work??
In addtion to what others said, you can use the Convert module, that does type convertions between various types. It uses the to!( TargetType ) template function import tango.util.Convert; int x = 37 char[] y = to!(char[])(x);
Jan 30 2008
There actually is a third way.
You can use the formatter
import tanto.text.convert.Format;
int x = 37;
char[] y1 = Format( "{} = 0x{:X4}", x ); // "37 = 0x0025"
Jan 30 2008
Frank Benoit Wrote and Ty Tower thanks him and all the others for their replies I found the convert module easiest to follow as a newbie-thanks
Jan 30 2008









Lutger <lutger.blijdestijn gmail.com> 