Solved

Number to an Array C#

Posted on 2006-11-30
3
246 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:jmkotman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
lmedwilliams earned 500 total points
ID: 18049664
I assume you are trying to break apart a single string.

Simply iterate through the string with an index.

So for example "00153" as the value for number1, written in code as number1[0] would return 0, and number1[4] would give you a 3.

Note the index starts at 0, and there is an extra LF/CR at the end (number1[5,6]), which will return a value, just not a number.

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18049916
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?
0
 
LVL 10

Expert Comment

by:tpwells
ID: 18055730
"00153".ToCharArray() will give you a char array

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help making a program or form for inventory that exports to txt 8 47
SQL Insert parts by customer 12 52
convert Systemjs to Webpack 3 73
"lblTime is not declared" 3 29
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question