toAlpha

Translates an integer into an alphanumeric string. Assumes ASCII. Overload that returns the string.

Merely leverages toAlphaInto.

@safe pure
string
toAlpha
(
size_t maxDigits = 19
uint leadingZeroes = 0
Num
)
(
const Num num
)

Parameters

maxDigits

The maximum number of digits to expect input of.

leadingZeroes

The minimum amount of leading zeroes to include in the output, mirroring the format specifier "%0nd".

num Num

Integer to translate into string.

Return Value

Type: string

The passed integer num in string form.

Examples

int num = 12345;
string asString = num.toAlpha;
assert(asString == "12345");
assert(asString == num.to!string);
{
    enum num = 123_456;
    immutable translated = num.toAlpha;
    assert((translated == "123456"), translated);
}
{
    enum num = 0;
    immutable translated = num.toAlpha;
    assert((translated == "0"), translated);
}
{
    enum num = 999;
    immutable translated = num.toAlpha;
    assert((translated == "999"), translated);
}
{
    enum num = -987;
    immutable translated = num.toAlpha;
    assert((translated == "-987"), translated);
}
{
    enum num = 123;
    immutable translated = num.toAlpha!(12, 6);
    assert((translated == "000123"), translated);
}
{
    enum num = -1;
    immutable translated = num.toAlpha!(3, 3);
    assert((translated == "-001"), translated);
}
{
    enum num = -123_456_789_012_345L;
    immutable translated = num.toAlpha!15;
    assert((translated == "-123456789012345"), translated);
}
{
    enum num = long.min;
    immutable translated = num.toAlpha;
    assert((translated == "-9223372036854775808"), translated);
}