日期:2014-05-17 浏览次数:20884 次
string str = "大家好,我是Hebe,我22岁了,身高180,我们团队有3个女女!";
var list = Regex.Matches(str, @"\d+(\.\d+)?").OfType<Match>().Select(t => t.Value).ToList();
list.ForEach(t => Console.WriteLine(t));
string str = "大家好,我是Hebe,我22岁了,身高180,我们团队有3个女女!";
List<int> lst = new List<int>(); //存放提取的数据
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= '0' && str[i] <= '9')
{
int x = i, y;
for (int j = i + 1; j < str.Length; j++)
{
if (str[j] < '0'
------解决方案--------------------
str[j] > '9')
{
y = j;
lst.Add(int.Parse(str.Substring(x, y - x)));
i = y;
break;
}
}
}
}