www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - integer to string

reply Simon Hobbs <Simon_member pathlink.com> writes:
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
Jul 14 2004
next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
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.
Jul 14 2004
prev sibling parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
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

 heavy and I'd rather not start importing C libraries if I can help it.

 Thanks

 Si

Jul 14 2004
parent Simon Hobbs <Simon_member pathlink.com> writes:
Thanks chaps.
Jul 14 2004