Finding the string length of a integer in .NET
Posted
by James Newton-King
on Stack Overflow
See other posts from Stack Overflow
or by James Newton-King
Published on 2010-03-24T09:23:09Z
Indexed on
2010/03/24
9:33 UTC
Read the original article
Hit count: 405
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
99 = 2 characters
100 = 3 characters
1000 = 4 characters
The obvious answer is to convert the int to a string and get its length but I want the best performance possible without the overhead of creating a new string.
© Stack Overflow or respective owner