digitalmars.D.learn - Integer to String
- tytower (4/4) Jan 30 2008 I'm pulling my hair out to simply take a number say 37 and convert it to...
- Lutger (6/13) Jan 30 2008 see http://www.dsource.org/projects/tango/wiki/ChapterConversions#Intege...
- naryl (9/14) Jan 30 2008 http://www.dsource.org/projects/tango/wiki/ChapterConversions#Conversion...
- bearophile (14/17) Jan 30 2008 That sounds too much deep, what about something like:
- Lutger (1/1) Jan 30 2008 import tango.group.Convert;
- Frank Benoit (8/14) Jan 30 2008 In addtion to what others said, you can use the Convert module, that
- Frank Benoit (5/5) Jan 30 2008 There actually is a third way.
- ty tower (2/2) Jan 30 2008 Frank Benoit Wrote and Ty Tower thanks him and all the others for their ...
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 =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
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