[英]split String accept some characters
I have some trouble with split string. 我在拆分字符串时遇到了一些麻烦。
My String: 我的字串:
"SG_ PJB_ : 1|10@0+ (0.25,-60) [-60|195.75] "Degrees Celcius" PCM,TCM,AFCM";
I would like to have: 我想拥有:
SG_
PJB_
1
10
0+
0.25
-60
-60
195.75
Degrees Celcius
PCM
TCM
AFCM
my Code i have tried: 我尝试过的代码:
string s = "SG_ PJB_ : 1|10@0+ (0.25,-60) [-60|195.75] \"Degrees Celcius\" PCM,TCM,AFCM";
string[] res = s.Split(new char[] { ' ', ',', ':', '|', '@', '(', ')', '[', ']', ';' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < res.Length; i++)
{
// Console.WriteLine(" ");
Console.WriteLine("{0}", res[i]);
}
Console.ReadKey();
But it splited "Degrees Celcius" in 2 arrays. 但是,它将“度摄氏”分为两个阵列。 what should i do?
我该怎么办?
Use this way: 使用这种方式:
var result = input.Split(new[] { '"' }).SelectMany((s, i) =>
{
if (i%2 == 1) return new[] {s};
return s.Split(new[] { ' ', ',', ':', '|', '@', '(', ')', '[', ']', ';' },
StringSplitOptions.RemoveEmptyEntries);
}).ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.