Finding the string length of a integer in .NET

后端 未结 6 654
小鲜肉
小鲜肉 2020-12-28 18:12

In .NET what is the best way to find the length of an integer in characters if it was represented as a string?

e.g.

1 = 1 character
10 = 2 characters

6条回答
  •  情深已故
    2020-12-28 18:16

    If input is in range 0-10000

    if (i < 10) return 1;
    if (i < 100) return 2;
    if (i < 1000) return 3;
    if (i < 10000) return 4;
    // etc
    

提交回复
热议问题