简体   繁体   中英

How can i split first 2 words of string dynamic c#

i need to split first 2 words of dynamic string.

string ex: 11 PM EDT WED JUL 11 2001

string ex: 1100 PM AST TUE AUG 18 2015

string ex: multi formats

I need split like this:

str1:  11 PM
str2:  1100 PM

my code:

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

result:

11
11

尝试这个 :

myResults[3] = resultList[4].Split('M')[0] + "M";

Please try this code.

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM