1
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            item = comboBox1.SelectedIndex.ToString();
        }

When doing SelectedIndex so in this case item = "0" Then i'm doing:

CreateMainDirectory(int.Parse(item));

So in CreateMaindirectory the number is 0. But the first index/item in the comboBox is:

"Reduced by: 10"

So i want to parse the number 10. So in CreateMainDirectory should be the number 10.

And if i'm doing:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            item = comboBox1.SelectedItem.ToString();
        }

Then item is: "Reduced by: 10"

How can i parse the number 10 if i'm using SelectedIndex and/or SelectedItem ?

  • 2
    You want to get only integer part in a string? http://stackoverflow.com/questions/4734116/find-and-extract-numbers-from-a-string – Soner Gönül May 17 '14 at 18:57

2 Answers2

2
item = new string(item.Where(char.IsDigit).ToArray());

Or:

item = item.Split().Last();

If the number is always at the end of the string.

Selman Genç
  • 100,147
  • 13
  • 119
  • 184
2

You can use this

numberString = Regex.Match(mainString, @"\d+").Value;

[\d+ is regex for numbers ] thn Int32.Parse(numberString ) will give you the actual number

souvickcse
  • 7,742
  • 5
  • 37
  • 64