C#中我想提下拉框里的内容 截取 0-14岁 - 两边的数字,但不要岁字

来源:百度知道 编辑:UC知道 时间:2024/06/17 13:02:05
我要取 - 两边的数字 但不要”岁“字 下拉框里的内容 0-14岁.15-22岁.23-27岁.27-30岁 我要在每一项里取他们的两个数字,要用的好像是截取字符串,我应该怎么做,我只是想把两个数字取出来赋两个值。

for (int i = 0; i < comboBox1.Items.Count; i++)
{
string a = comboBox1.Items[i].ToString();
string b=a.Replace("岁", string.Empty);
string[] c = b.Split('-');

MessageBox.Show(c[0]+" "+c[1]);
}

string a = 获取字符串.trim("岁");
string[] array = a.split("-");
string first = array[0];
string second = array[1];

我刚才给你的那段代码不好使吗?
string a = "0-14岁";
string b = a.Replace("岁", string.Empty);
string[] str = b.Split('-');
string c = str[0]; //这行的值为0;
string d = str[1]; //这行的值为14;

可以从左到右截取指定位就是你说的数字 存到变量就行