Thursday, March 22, 2012

Optimize Method

I have the following method to format a string.

private string FormatString(string input) { input = input.Replace(',',' '); input = input.Replace('.',' '); input = input.Replace(" ","-"); input = input.Replace(" ","-"); input = input.Replace("--","-");return HttpUtility.HtmlDecode(input); }

How can I optimize it to do what I want quicker? Regular Expression?

input = RegEx.Replace(input, ",|,.|\s|\s\s|--", "-");

I belive will get you what you need.

0 comments:

Post a Comment