[.net] [C#] Cycle Through Digits
Is there a way to cycle through the digits of, say, an int value and read each digit as if it were one number?
Should be something like ...
Regards,
ViLiO
int foo = 987654321;string bar = foo.ToString();for(int i=0; i<bar.Length; ++i){ Console.WriteLine(bar.Substring(i,1));}
Regards,
ViLiO
Quote:Original post by Uphoreum
So you have to convert it to a string first?
You don't have to, no [smile]
You could do it like this...
int foo = 987654321;while (foo > 0){ int digit = foo % 10; foo /= 10; Console.WriteLine(digit);}
Regards,
ViLiO
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement