Thursday, March 1, 2012

CSharp: replace string using regex pattern

Share at Facebook

I use regular expression extensively. So this is my favorite function for replacing a string. Basically code will remove all digits from the given string.

x = Regex.Replace(x, @"\d+", "");

Or everything after starting the digit.
x = Regex.Replace(x, @"\d.*$", "");

No comments: