English 中文(简体)
整数转换为 D 字符串转换
原标题:integer to string conversion in D

How in D would I cast integer to string? Something like

int i = 15
string message = "Value of  i  is " ~ toString(i); // cast(string) i - also does not work 

Google给我带来了如何使用探戈的答案, 但我想要Phobos版本。

最佳回答
import std.conv;

int i = 15;
string message = "Value of  i  is " ~ to!string(i);

format :

import std.string;
string message = format("Value of  i  is %s.", i);
问题回答

使用 std. conv 的 < code> 到 :

int i = 15
string message = "Value of  i  is " ~ to!string(i);
import std.conv;
auto i = 15;
auto message = text("Value of  i  is ", i);

巫婆返回符纹和符纹。





相关问题
Delphi: generics and is -operator problem

Based on an earlier post, I ve written the following code. Please excuse the verbosity of this post. I believe it s better for all parties to have the full code available to test and comment on. ...

How to use argument in a cast with Delphi

How to do this in Delphi: procedure ToggleVisibility(ControlClass : TControlClass); var i : integer; begin for i := 0 to ComponentCount - 1 do if Components[i] is ControlClass then ...

Complicated C cast explanation

I m trying to figure out what the following code in C does? ((void(*)())buf)(); where buf is a char array.

Beginner: Extending a class in C#, am I doing it wrong?

Again disclaimer disclaimer still learning C# and OOP generally so I hope you ll be patient with me :) I am currently working with a CMS that has a class called FileVersion which basically contains a ...

Casting generic object array to two types

I ve got a method that receives an Object[] and then performs actions on that array. At first I was passing in this array as an IEnumerable<T> however the T can be of two different types. The ...

热门标签