Hey guys,
I need to find the length of a long variable (how many numbers it holds).
So if the variable holds: '1234567890' then I want to return an int value
of '10'. varName.Length() doesn't work, and I haven't found anything from
google or msdn.

Thanks for the help,

- WolfShield

I need to find the length of a long variable (how many numbers it holds). So if the variable holds: '1234567890' then I want to return an int value
of '10'.

One way to do this is with Math.Log10. There's a trick to getting the right answer, though... look at the example output on the linked page for clues.

int length = myLongVar.ToString().Length;

Or:

string example = "0123456789";
int count = example.Length;

@Mitja Bonca:
Your answer does not solves the question.
Your string length is 10, while the equivalent long length is only 9.

int length = myLongVar.ToString().Length;

Thanks you! Works like a charm!

- WolfShield

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.