Is there a better way to do this ...
MyString.Trim().Replace("&", "and").Replace(",", "").Replace(" ", " ") .Replace(" ", "-").Replace("'", "").Replace("/", "").ToLower();
I have expanded the class of strings to prevent it from reaching one job, but is there a faster way?
public static class StringExtension { public static string clean(this string s) { return s.Replace("&", "and").Replace(",", "").Replace(" ", " ") .Replace(" ", "-").Replace("'", "").Replace(".", "") .Replace("eacute;", "Γ©").ToLower(); } }
Just for fun (and for stopping the arguments in the comments) I popped the entity by comparing various examples below.
https://gist.github.com/ChrisMcKee/5937656
The regex parameter is terribly evaluated; Dictionary selection is the fastest; the long-winded version of the string substitute is slightly faster than the short one.
string immutability c # refactoring
Chris McKee Aug 24 '09 at 9:25 2009-08-24 09:25
source share