[Solved] how to create a string like regex


You can simple use ToString with parameter:

private string getResult(int x)
{
    return x.ToString("0000"); 
}

from @Dmitry Bychenko :

You can also use "D4" as parameter instead of "0000" with same results.

This solution also works with negative numbers instead of PadLeft method.

1

solved how to create a string like regex