• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1432
  • Last Modified:

convert comma delimited string from textbox to decimal??

I have a textbox where users will enter in an unknown amount comma delimited numbers and I then need to process that textbox string as numbers.

 How do I convert that string to decimal numbers?  Should I use an arraylist or what to handled the numbers?

3 Solutions
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use something like...

        private void button1_Click(object sender, EventArgs e)
            decimal dec;
            string[] numbers = textBox1.Text.Split(",".ToCharArray());
            foreach (string number in numbers)
                    dec = Decimal.Parse(number);
                    // do something with "dec"
                catch (Exception ex)
                    MessageBox.Show(number, ex.Message, MessageBoxButtons.OK );                    
sure, if you want to just populate them into an array  you could do something like this:

String str = "15.45, 43.5";  //str = myTextBox.Text;
String[] arr = str.Split(',');
ArrayList arrTemp = new ArrayList();
for(int i=0; i<arr.Length; i++)
You may want to consider a different interface, since many people will enter:

1,350.56 as a single number

Not as two different numbers 1 and 350.56
wheels4meAuthor Commented:
Thanks for the help.  I split the points since all the answers had value to them.  I figured out what I was trying to do before I got the answer.  What I used was close to the second answer -- String[] arr = str.Split(',').

It was a homework assignment for school and at first I thought it read that we had to use an ArrayList, further investigation found that I could create an array and not assign it a length until run-time/data entry.

Thanks for the help.  It has been a couple of years since I used EE and I am glad to see that it works as well as ever.

Thanks again,

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now