-2

Hello i am trying to process character arrays. I want to assign the number 50 as string value "00050". How can I do it ?

enter code here
 string strRpc(int NumstrRpcSendLen)
    {
        int digit =  Convert.ToInt32( Math.Floor(Math.Log10(NumstrRpcSendLen + 5) + 1));
        int len = 0;
        char[] d = new char[5];
        string result= null;


        while (len<5)
        {
            if (len<digit)
            {
                d[len] = '0';
            }
            else
            {




            }

            len++;
        }

        return result;

       }
Murat Drm
  • 1
  • 1
  • 1
    Um, `string text = number.ToString("00000");`? No need to do all this manually. I'd also strongly advise learning about .NET naming conventions. – Jon Skeet Apr 05 '17 at 10:29

2 Answers2

0

I'm not sure what your code is doing, but there's a string format specifier for that:

var x = 50.ToString("D5");
//x = "000050"

Look at the documentation for more help

Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
0

You could try it

var result = 50.ToString("00000");
TriV
  • 5,118
  • 2
  • 10
  • 18
  • 1
    Although this code might answer the question, one should always add an explanation why/how the problem is solved. – BDL Apr 05 '17 at 11:06