C# convert int to string with padding zeros?

前端 未结 13 1776

In C# I have an integer value which need to be convereted to string but it needs to add zeros before:

For Example:

int i = 1;

When

13条回答
  •  不思量自难忘°
    2020-11-22 06:59

    public static string ToLeadZeros(this int strNum, int num)
    {
        var str = strNum.ToString();
        return str.PadLeft(str.Length + num, '0');
    }
    
    // var i = 1;
    // string num = i.ToLeadZeros(5);
    

提交回复
热议问题