我有一些拆分字符串的問題。拆分字符串接受一些字符
我的字符串:
"SG_ PJB_ : 1|[email protected]+ (0.25,-60) [-60|195.75] "Degrees Celcius" PCM,TCM,AFCM";
我想有:
SG_
PJB_
1
10
0+
0.25
-60
-60
195.75
Degrees Celcius
PCM
TCM
AFCM
我的代碼,我曾嘗試:
string s = "SG_ PJB_ : 1|[email protected]+ (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();
但在2個陣列splited 「攝氏度」 。我該怎麼辦?
'度Celcius'有一個空間在那裏。當然它分裂了。你不能在一個'string.Split'中實現你所要求的。 – Oded
我應該做2分裂嗎?將firstordeufault劃分爲「lastordefaut from」? –
你可以在'''上分割,然後在第一個'''之前分割東西,然後在其他項目之後分割東西,然而,這個假設你只會在字符串中有一對'「' 。 – Oded