Why is there no Char.Empty like String.Empty?

Viewed 304152

Is there a reason for this? I am asking because if you needed to use lots of empty chars then you get into the same situation as you would when you use lots of empty strings.

Edit: The reason for this usage was this:

myString.Replace ('c', '')

So remove all instances of 'c's from myString.

23 Answers

If you look at the documentation for Replace(String, String) overload for String.Replace you can see in the remarks section that if the second argument is a null then it will remove all instances of what you specified. Therefore if you just use myString = myString.Replace("c", null); it will delete every c in the string.

here is how we do it : myString.Replace ('''.ToString(), "");

public static string QuitEscChars(this string s) 
{
    return s.Replace(((char)27).ToString(), "");
}
Related