C# 如何拆分字符串dynamic c的前两个单词#

C# 如何拆分字符串dynamic c的前两个单词#,c#,string,split,C#,String,Split,我需要拆分动态字符串的前两个单词 string ex: 11 PM EDT WED JUL 11 2001 string ex: 1100 PM AST TUE AUG 18 2015 string ex: multi formats 我需要这样的拆分: str1: 11 PM str2: 1100 PM 我的代码: int o = 1; myResults[3] = ""; while (resultList[4].Substring(0, o++).Last() != '

我需要拆分动态字符串的前两个单词

string ex: 11 PM EDT WED JUL 11 2001

string ex: 1100 PM AST TUE AUG 18 2015

string ex: multi formats
我需要这样的拆分:

str1:  11 PM
str2:  1100 PM
我的代码:

int o = 1; myResults[3] = "";
    while (resultList[4].Substring(0, o++).Last() != 'M')
            myResults[3] = resultList[4].Substring(0, o).Trim(); //Time
结果:

11
11
试试这个:

myResults[3] = resultList[4].Split('M')[0] + "M";
请尝试此代码

string a="11 PM EDT WED JUL 11 2001";
    int firstSpace = a.IndexOf(" ")+1;
    int secondSpace = a.IndexOf(" ", firstSpace);
    Console.WriteLine(a.Substring(0, secondSpace));

你说的“动态字符串”是什么意思?我指的是多格式(数字+AM | | | PM)的进程,
string[]splitted=ex.Split(“”)
?然后您可以通过
拆分[0]
获取第一个单词,通过
拆分[1]
获取第二个单词;myResults[3]=timeSp[0]+“”+timeSp[1]//Time@sukhoi191我把它和URL一起使用,忘了和这个一起使用=)谢谢,字符串a是动态字符串