string help in

Posted on 2006-04-24
Last Modified: 2010-04-16
I've got 3 sets of radio buttons on an page and need to parse out the string that is returned when a user makes a selection.

8700  $199.99  12
7105  $99.99   12
7290  $49.99   12

The value for each looks like: 8700199.9912

string modelpricemonth;
string variableModel; // = 8700
string variablePrice; // = 199.99
string variableMonth; // = 12

modelpricemonth = ModelType.SelectedItem.Value;
LabelSummary.Text = modelpricemonth; //8700199.9912

LabelModel.text = variableModel;
LabelPrice.text = "$" + variablePrice;
LabelMonths.text = variableMonth;

How do I get this result?

LabelModel.Text = 8700
LabelPrice.Text = $199.99
LabelMonths.Text = 12

Question by:fwsteal
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Will the model ALWAYS be four digits?

    Will there ALWAYS be two digits after the decimal place?
    LVL 12

    Expert Comment

    excellent questions idle maind. can't helkp without knowing these

    Author Comment

    yes and yes, those formats will always be the same

    Author Comment

    constant values; sorry new to c#
    LVL 62

    Accepted Solution

    Hi fwsteal;

    Here is a sample code that will do what you want using Regular Expression.

    using System.Text.RegularExpressions;

          string data = "8700199.9912";
          string Model = "";
          string Price = "";
          string Month = "";
          Match m = Regex.Match(data,
          if( m.Success )
                Model = m.Groups["Model"].Value;
                Price = m.Groups["Price"].Value;
                Month = m.Groups["Month"].Value;
                MessageBox.Show("Model = " + Model + " Price = $" + Price +
                      " Month = " + Month);

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    You could also do...

                string modelpricemonth = "8700199.9912";
                int period = modelpricemonth.IndexOf(".");
                string variableModel = modelpricemonth.Substring(0,4);            
                string variablePrice = modelpricemonth.Substring(4, period - 4 + 3);
                string variableMonth = modelpricemonth.Substring(period + 3);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now