I want to split a string

i want to split a string like “ravi gupta add a notesdec 29 2019 11:00:00”
i want only “dec 29 2019 11:00:00” only the date how can i do it
how can i do it
thanks in advance

1 Like

Hi @ravi_gupta,

Please assign new_string = System.Text.RegularExpressions.Regex.Match(your_string,"\w{3}\s\d{1,2}\s\d{4}\s\d{1,2}:\d{1,2}:\d{1,2}").ToString

Warm regards,
Nimin

3 Likes

hi @ravi_gupta

you may read and learn how to split the string in detail at below link

3 Likes

i have tried many time to split it but it not splitting extact what i want

1 Like

thank you its worked…can u explain this i am beginner please

1 Like

is there any other alternative way to split without using split method
thank you in advace.

1 Like

Hi @ravi_gupta,
In your string, " “ravi gupta add a notesdec 29 2019 11:00:00”, we need to extract only the dates, which is in the format “CCC<space>DD<space>DDDD<space>DD:DD:DD”, where D is a single digit and C is a single character. Whatever will be the string, the regex “\w{3}\s\d{1,2}\s\d{4}\s\d{1,2}:\d{1,2}:\d{1,2}” captures only the specified pattern. In regex,’\w’ is any word or digits, ‘\s’ is a white-space character and numbers inside { } specifies the occurrence of the previous regex. That is, ‘\w{3}’ is 3 occurrence of any number or characters and '\d{1,2}; represents 1 or 2 occurrence of any digit. I hope you got the idea now.:wink:

You can also use split or substring method to achieve this. But there must be one or more static characters or strings to use as a delimiter. In your case, your_string.Split({"notes"},stringsplitoptions.None)(1) can be use to get the dates, but the condition is, the date must comes after the word ‘notes’.

Warm regards,
Nimin

3 Likes

thank you sir for ur help …the problen is solved.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.