一:传统写法
string num = "";
string pre = "";
bool ha = true;
ArrayList fig = new ArrayList();
for (int i = 0; i < str.Length; i++)
{
if (IsNumber(str[i].ToString()) || str[i].ToString() == ".")
{
num += str[i];
ha = false;
}
else if (ha)
{
num += " ";
pre += str[i];
}
else { num += " "; }
}
public static bool IsNumber(string s)
{
bool isNumber = int.TryParse(s, out int numericValue);
return isNumber;
}
二:简洁写法
List<string> STR_MY = new List<string>();
string str1 = Regex.Replace(str, @"[^\d.\d]", " ").Trim();
string[] mystr = Regex.Split(str1, " ", RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(500));//通过空格提取数据
string pre = str[..str.IndexOf(mystr[0])];
STR_MY.Add(pre);
for (int i = 0; i < mystr.Length; i++)
{
STR_MY.Add(mystr[i]);
}