Find date from string

shrona

Member
Joined
Apr 20, 2012
Messages
5
Programming Experience
Beginner
Accept the string from the user.


Find the date from the given string with ddmmyyyy format and display the output as:"date found = "
Eg:input:Eg: abc0712201345bye
output:date found =07122013
how to do this?
 
Hi,

I would suggest using RegEx with a typical string like this but I am a bit concerned at the moment due to the extra Digits at the end of that Date which you are trying to extract.

So, before I provide an example:-

1) How does that date in the string start? Is it always after a letter or can it also be after another number or space?

2) Is the date always 8 digits in length? i.e:- 2 digits for the day and month, then 4 digits for the year?

3) Obviously, the date can have extra numbers at the end, but can this also be any alpha-numeric character?

Cheers,

Ian
 
If there can be other 8-digit values in the string that is not Date values you could use Date.TryParseExact method to validate the regex matches.
 
Back
Top