From the course: C# and .NET Essential Training
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Solution: Regular expressions - C# Tutorial
From the course: C# and .NET Essential Training
Solution: Regular expressions
- [Instructor] For this challenge, we needed to transpose a date using regular expressions. So in my solution, if we look over here in the answer panel, I defined a helper function named ReverseDateFormat that takes a single string argument, and we'll come back to this function in a few moments. So my ReverseDate function takes the input string and makes sure that it is a valid date before trying to reverse the format by using the TryParse function. So if the date is valid, then I pass the string to my ReverseDateFormat function. And for invalidates, I return an empty string, which, again, was part of the challenge requirements. And we are going to test our code against these strings down here. So let's go examine how that ReverseDateFormat function works. So following a defined best practice, I specify a timeout value for my regular expression. And then I'm going to use the static Replace function on the Regex class to execute the regular expression that I want to use to transpose…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.