Link to home
Start Free TrialLog in
Avatar of jmkotman
jmkotmanFlag for United States of America

asked on

Number to an Array C#

If I have a number, say 00153 which i have read in and it is set to a string variable 'number1'.

So number1 = 00153;

How do i convert that into an array so that each numbers is a diffrent element in the array.
ASKER CERTIFIED SOLUTION
Avatar of lmedwilliams
lmedwilliams

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Tomlinson
Do you want a string array?

            string number1 = "00153";

            string[] digits = new string[number1.Length];
            for (int i = 0; i < number1.Length; i++)
            {
                digits[i] = number1.Substring(i, 1);
            }

            foreach (string digit in digits)
            {
                System.Diagnostics.Debug.WriteLine(digit);
            }

Or did you want an Array of ints?
Avatar of tpwells
tpwells

"00153".ToCharArray() will give you a char array

if the variable is strTest then
char[] fields = strTest.ToCharArray();