OK, what do you expect?
Do you want to replace anything with nothing? What exactly do you want to do?
Say the old line was "ABC", what would you like it to be after your call to Replace ?
In this particular case, an exception is thrown by ArgumentException , and its text is that "the string cannot be zero length".
So, the criteria for calling the .Replace method is that what you want to replace is not a string without content.
Let me check the documentation of String.Replace (String, String) :
The Exceptions say:
ArgumentNullException if oldValue is a null reference (Nothing in Visual Basic).
or
ArgumentException if oldValue is an empty string ("").
So, everything behaves as expected.
source share