Haxe Int to String

It seems AS3 has toString() for the Number class. Is there an equivalent in Haxe? The only solution I could come up with for converting Int to String is a function like:

 public function IntToString(i:Int):String { var strbuf:StringBuf = new StringBuf(); strbuf.add(i); return strbuf.toString(); } 

Is there a better method that I skip?

+10
string haxe
source share
1 answer

Usually you do not need to manually convert int to string, because the conversion happens automatically.

 var i = 1; var s = "" + i; // s is now "1" 

The β€œformal” way to convert any value to a string is to use Std.string() :

 var s = Std.string(i); 

You can also use string interpolation :

 var s = '$i'; 

The function you wrote is good, but definitely redundant.

+18
source share

All Articles