C# 如何仅从item解析数字并将数字放入int变量中?

C# 如何仅从item解析数字并将数字放入int变量中?,c#,winforms,C#,Winforms,执行此操作时,在本例中选择索引“0” 然后我在做: private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { item = comboBox1.SelectedIndex.ToString(); } "Reduced by: 10" 所以在CreateMain目录中,数字是0。 但组合框中的第一个索引/项是: CreateMainDirectory

执行此操作时,在本例中选择索引“0” 然后我在做:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            item = comboBox1.SelectedIndex.ToString();
        }
"Reduced by: 10"
所以在CreateMain目录中,数字是0。 但组合框中的第一个索引/项是:

CreateMainDirectory(int.Parse(item));
所以我想解析数字10。所以在CreateMain目录中应该是数字10

如果我正在做:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            item = comboBox1.SelectedIndex.ToString();
        }
"Reduced by: 10"
然后项目是:“减少:10”

如果使用SelectedIndex和/或SelectedItem,如何解析数字10

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

如果数字始终位于字符串的末尾

或:

如果数字总是在字符串的末尾。

您可以使用此选项

item = item.Split().Last();
[\d+是数字的正则表达式] thn Int32.Parse(numberString)将为您提供实际的数字

您可以使用此

item = item.Split().Last();
[\d+是数字的正则表达式]
thn Int32.Parse(numberString)将给出实际的数字

是否只获取字符串中的整数部分?您想只获取字符串中的整数部分吗?