How to extend C# built-in types, like String?

Greetings everyone... I need to Trim a String. But I want to remove all the repeated blank spaces within the String itself, not only at the end or at the start of it. I could do it with a method like:

public static string ConvertWhitespacesToSingleSpaces(string value)
{
    value = Regex.Replace(value, @"\s+", " ");
}

Which I got from here. But I want this piece of code to be called within the String.Trim() itself, so I think I need to extend or overload or override the Trim method... Is there a way to do that?

Thanks in advance.

83
задан Hogan 14 May 2011 в 13:36
поделиться