Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# convert comma delimited string from textbox to decimal??

Posted on 2006-06-09
Medium Priority
1,425 Views
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?

TIA
0
Question by:wheels4me
[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

LVL 86

Assisted Solution

Mike Tomlinson earned 500 total points
ID: 16872457
Use something like...

private void button1_Click(object sender, EventArgs e)
{
decimal dec;
string[] numbers = textBox1.Text.Split(",".ToCharArray());
foreach (string number in numbers)
{
try
{
dec = Decimal.Parse(number);
// do something with "dec"
System.Diagnostics.Debug.WriteLine(dec.ToString());
}
catch (Exception ex)
{
MessageBox.Show(number, ex.Message, MessageBoxButtons.OK );
}
}
}
0

LVL 7

Accepted Solution

prosh0t earned 500 total points
ID: 16872476
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++)
{
}
0

LVL 35

Assisted Solution

mrichmon earned 200 total points
ID: 16872490
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
0

Author Comment

ID: 16874467
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,

Kevin
0

## Featured Post

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month8 days, 2 hours left to enroll