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
You could use something like this:
int integer = 100; int charachtersCount = 0; while (integer > 0) { integer = integer/10; charachtersCount++; }
But do you really need to optimize this? I would actually prefer using string (looks much better):
integer.ToString().Length