Converting string to int without losing the zero in the beginning

后端 未结 10 460
Happy的楠姐
Happy的楠姐 2021-01-02 03:49

I tried int.parse, and convert class to convert a string to int.

While I\'m converting. I\'m losing the 0 in the beginning which i don\'t want.

10条回答
  •  再見小時候
    2021-01-02 04:10

    Although this is a old thread, but this can also help:

    // convert to big integer
    var bigIntBits = BigInteger.Parse(intNumber);
    int indexOfOne = intNumber.IndexOf('1');            
    string backToString = new string('0', indexOfOne) + bigIntBits.ToString();    
    

提交回复
热议问题