www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to cast a int to a string?

reply "Chris Pons" <cmpons gmail.com> writes:
I'm trying to update a string easily whenever I change a numeric 
component of the string. I've tried to do this so far with no 
result:

while( testInt < 10 )
string testString = "Test ";
int testInt = 0;
testString ~= toString(testInt)
testInt++;

or this:

testString ~= cast(string)(testInt)

Both of these give an error.

This however does not, but it also doesn't seem to update 
testString

I've also tried this:

testString ~= cast(char)(testInt);

It doens't throw an error, but it doesnt' seem to work either.

For the record, i'm not using writln to print to console, this is 
through SDL and OpenGL so it should be a string.
Mar 06 2012
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Mar 07, 2012 at 12:13:54AM +0100, Chris Pons wrote:
 I'm trying to update a string easily whenever I change a numeric
 component of the string. I've tried to do this so far with no
 result:
[...] Try this: import std.conv; ... int i = 1234; string s = to!string(i); T -- Recently, our IT department hired a bug-fix engineer. He used to work for Volkswagen.
Mar 06 2012
parent "Chris Pons" <cmpons gmail.com> writes:
On Tuesday, 6 March 2012 at 23:19:03 UTC, H. S. Teoh wrote:
 On Wed, Mar 07, 2012 at 12:13:54AM +0100, Chris Pons wrote:
 I'm trying to update a string easily whenever I change a 
 numeric
 component of the string. I've tried to do this so far with no
 result:
[...] Try this: import std.conv; ... int i = 1234; string s = to!string(i); T
Thanks, that did the trick.
Mar 06 2012