www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Integer to String

reply tytower <tytower yahoo.com> writes:
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
next sibling parent Lutger <lutger.blijdestijn gmail.com> writes:
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
prev sibling next sibling parent reply naryl <cy ngs.ru> writes:
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 =
to =
 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
parent reply bearophile <bearophileHUGS lycos.com> writes:
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
parent Lutger <lutger.blijdestijn gmail.com> writes:
import tango.group.Convert;
Jan 30 2008
prev sibling parent reply Frank Benoit <keinfarbton googlemail.com> writes:
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
next sibling parent Frank Benoit <keinfarbton googlemail.com> writes:
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
prev sibling parent ty tower <tytower yahoo.com.au> writes:
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