C#Split从字符串中提取数值

2024-12-30 06:34:28
推荐回答(3个)
回答1:

自己把split再封装一下不就行了,如下:
private string[] mySplit(string str){
str=str.Replace("/t",",");
str=str.Replace(" ",",");
string[] rel = str.Split(',');
return rel;
}
string[] arrs = mySplit("04 -2446371.03605 4237238.92861 4078014.49803");

回答2:

Split从字符串 针对的是单个的字符串,您这里如此多的 数据,
要提取四个有用的数据, 可以用正则表达式 ~~~~~~~
额~~~具体的 正则匹配规则 我也不会,但是 正则一定可以~~~~~~~~~

回答3:

提供个思想
private void button1_Click(object sender, EventArgs e)
{
string s = " 04 -2446371.03605 4237238.92861 4078014.49803"
+ " 05 -3144971.82317 , 3748031.46887 -4077985.57259"
+ " 06 -851214.97690 714254.17317 6259641.44240";
//string[] a = s.Split(new string[] { " ", ",", "\t" }, StringSplitOptions.RemoveEmptyEntries);
string[] a = s.Split(new char[] { ' ', ',', '\t' }, StringSplitOptions.RemoveEmptyEntries);
}

希望回答对你有帮助