[Resolved] String cannot be of zero length. Parameter name: oldValue
Dung Do Tien
Sep 26 2020
231
I have the code below when I replace variable text0 with text1. I got an error String cannot be of zero length. Parameter name: oldValue.
string text0 = string.Empty;
string text1 = "This is text 1";
string text2 = text1.Replace(text0, "");
Console.WriteLine(text2);
I don't know what is oldValue param? and How can I fix this issue?
Have 1 answer(s) found.
-
1
In c#/ Asp.net Core,
Replace()
method accepts two parameters as below:public String Replace(String oldValue, String? newValue);
In that,
oldValue
parameter is required and not accept value null or empty. In your exampletext0
variable is empty so it throws that exception. Please sure thattext0
must NOT null or empty.Marry Christ Sep 26 2020
If this answer is useful for you, please BY ME A COFFEE!!! I need your help to maintain blog.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.