Thread overview
Integer to String
Jan 30, 2008
tytower
Jan 30, 2008
Lutger
Jan 30, 2008
naryl
Jan 30, 2008
bearophile
Jan 30, 2008
Lutger
Jan 30, 2008
Frank Benoit
Jan 30, 2008
Frank Benoit
Jan 30, 2008
ty tower
January 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??
January 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);
January 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 = 37
> Char[] y = intToString(x);
>
> how the blazes do I make this simple little thing work??

http://www.dsource.org/projects/tango/wiki/ChapterConversions#Conversionbetweentextandnumerictypes

For your example:

import tango.text.convert.Integer;
...
int x = 37;
char[] y = toString(x);
January 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
January 30, 2008
import tango.group.Convert;
January 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);
January 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"



January 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