If I have string and I want to replace last character from that string with star for example.
I tried this
var myString = "ABCDEFGH";
myString.ReplaceCharacter(mystring.Length - 1, 1, "*");
public static string ReplaceCharacter(this string str, int start, int length, string replaceWith_expression)
{
return str.Remove(start, length).Insert(start, replaceWith_expression);
}
I tried to use this extension method but this doesn't work. Why this doesn't work?
The method, as it is, replace the character, but you have to catch the result
myString = myString.ReplaceCharacter(myString.Length - 1, 1, "*");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With