Thread overview
integer to string
Jul 14, 2004
Simon Hobbs
Jul 14, 2004
Stewart Gordon
Jul 14, 2004
Ben Hinkle
Jul 14, 2004
Simon Hobbs
July 14, 2004
Is there a simple way to convert an integer to a string?

I'm trying to do something along the lines of:

int i;
char[] s = "i = " ~ i;

The only thing I can see in phobos is the std.format stuff, but that's way too heavy and I'd rather not start importing C libraries if I can help it.

Thanks

Si


July 14, 2004
Simon Hobbs wrote:

> Is there a simple way to convert an integer to a string?
> 
> I'm trying to do something along the lines of:
> 
> int i;
> char[] s = "i = " ~ i;
> 
> The only thing I can see in phobos is the std.format stuff, but that's way too
> heavy and I'd rather not start importing C libraries if I can help it.

The undocumented function std.string.format makes it easy:

	char[] s = format("i = ", i);

Stewart.

-- 
My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment.  Please keep replies on the 'group where everyone may benefit.
July 14, 2004
import std.string;
...
char[] s = "i = " ~ toString(i);


"Simon Hobbs" <Simon_member@pathlink.com> wrote in message news:cd3f82$1ve2$1@digitaldaemon.com...
> Is there a simple way to convert an integer to a string?
>
> I'm trying to do something along the lines of:
>
> int i;
> char[] s = "i = " ~ i;
>
> The only thing I can see in phobos is the std.format stuff, but that's way
too
> heavy and I'd rather not start importing C libraries if I can help it.
>
> Thanks
>
> Si
>
>


July 14, 2004
Thanks chaps.