Thread overview | |||||
---|---|---|---|---|---|
|
March 06, 2012 How to cast a int to a string? | ||||
---|---|---|---|---|
| ||||
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. |
March 06, 2012 Re: How to cast a int to a string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris Pons | 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. |
March 06, 2012 Re: How to cast a int to a string? | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | 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.
|
Copyright © 1999-2021 by the D Language Foundation