Friday, July 22, 2011

Why use regular expression?

I never posted code I've come across, but reading a random code today, I started wondering why one couldn't use regular expressions below to accomplish the same result - maybe I am just missing some good reason for that, but I thought it might be amusing to share:

string[] stringArray = str.Replace("Jan, ", "Jan ").Replace("Feb, ", "Feb ").Replace("Mar, ", "Mar ").Replace("Apr, ", "Apr ").Replace("May, ", "May ").Replace("Jun, ", "Jun ").Replace("Jul, ", "Jul ").Replace("Aug, ", "Aug ").Replace("Sep, ", "Sep ").Replace("Oct, ", "Oct ").Replace("Nov, ", "Nov ").Replace("Dec, ", "Dec ").Split(new[] { ',' });
Post a Comment