Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacing string using extension method [closed]

Tags:

c#

.net

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?

like image 283
user2783193 Avatar asked Dec 24 '22 18:12

user2783193


1 Answers

The method, as it is, replace the character, but you have to catch the result

myString = myString.ReplaceCharacter(myString.Length - 1, 1, "*"); 
like image 63
adricadar Avatar answered Dec 27 '22 07:12

adricadar