string sub = null;
foreach (char c in str)
if (c >= '0') and (c <= '9')
sub += c;
else if (sub != null)
{
int.Parse(sub); // 取得数字
sub = null;
}
foreach (char c in str)
if (c >= '0') and (c <= '9')
sub += c;
else if (sub != null)
{
int.Parse(sub); // 取得数字
sub = null;
}
string b="";
foreach(char c in a)
{
b+=char.IsNumber(c)?c.ToString():"";
}
int count = 0; //记录一共有多少个数字单元(一个连续的数字串作为一个单元)
foreach (char c in str)
{
if ( char.IsDigit(c) )
{
sub += c;
}
else if (sub != null)
{
count++;
sub = null;
}
}sub = null;
int index = 0;
int[] Data = new int[count];
foreach (char c in str)
{
if ( char.IsDigit(c) )
{
sub += c;
}
else if (sub != null)
{
Data[index] = int.Parse(sub); // 取得数字
sub = null;
index++;
}
}这样Data[]数组里就包含了提取出来的一共count个数值。
实际上对string a="Φ32×3mm";类型要分别提取
32和3两个变量.
不过变通一下楼上几位方法也就实现了 ^O^