I'm a sydney based software developer. I currently build stuff with ruby, c# and objective-c.
This is part 2 of my series on making c# a nice language to work with. Previously I gave you flexible string quotation, today I present:
Regular Expressions as native types
Ever written code like this?
var money = Regex.Replace(@" $ 1,337", @"[\$\s\,]", "");
Regular expressions are so important to programming that they should be catered for in the language. At least Ruby and Javascript agree with me.
If c# understood regular expressions as a native type, we could have code like this:
var money = @" $ 1,337".Replace(/[\$\s\,]/, "")
You can instantly spot the regex, it doesn't have to be @ encoded into a string. We can also then have a replace method overload that takes a string or a regex type without any new Regex() bs.