Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

string help in asp.net

I've got 3 sets of radio buttons on an asp.net 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
-------------------------------------------------

code:
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

thanks
0
fwsteal
Asked:
fwsteal
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Will the model ALWAYS be four digits?

Will there ALWAYS be two digits after the decimal place?
0
 
gbzhhuCommented:
excellent questions idle maind. can't helkp without knowing these
0
 
fwstealAuthor Commented:
yes and yes, those formats will always be the same
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
fwstealAuthor Commented:
constant values; sorry new to c#
0
 
Fernando SotoCommented:
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,
            @"(?<Model>\d{4})(?<Price>\d+\.\d\d)(?<Month>\d+)");
      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);
      }


Fernando
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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);
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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