Well that title is a mouthful. Long story short, as an exercise in regular expressions I wrote a utility class to convert strings to TimeSpans and DateTimes in C#. This made great usage of named capturing groups. (The download to the source code is at the bottom of this post.)
Here is the DateTime regular expression. Note that when I new the regular expression object, I set whitespace and casing ignoring.
Named capturing groups allows code like this:
In the end, the utility class allows code like this:
fun! Download all of the code here.
Have any suggestions about the code? Any neat C# features I should have used? Comment below!
It’s been almost a year since I’ve updated FRI, my ROM library program. FRI is now officially dead, but not completely gone. Since I started working on FRI I have gained a lot more programming experience. I started writing the thing when I was still a C# novice. Between then and now I have written an elaborate intranet site in ASP.NET, debugged and written C++ applications, and have learned the true value of a regular expression. I look at FRI’s code now and am a little grossed out. I decided that if I was going to make any more improvements to FRI, I’d have to start over and rearchitect the whole thing. The name of this new project: Arcadia.
With Arcadia I have committed to research everything that I suspect will make for a better design. Because of this, Archaida’s backend is shaping up to be elegant and efficient. I researched how to do inheritance in C#, and have used that to save myself from writing a lot of code. This has drastically decreased development and testing time. I learned how to use basic regular expressions over the summer, and have used them in some areas (more on that later). For the frontend I decided to switch from WinForms to WPF. All I can say is that databinding is epic, and I still have a lot more to learn about it.
Here’s a shot of Arcadia in its current form: