How to remove all instances of a specific character from a string?
c#, string
Solution
You must assign the return value of `String.Replace` to your original string instance:
hence instead of(no need for the `Contains check)`
if (Gamertag2.Contains("^"))
{
Gamertag2.Replace("^" + 1, "");
}
just this(what's that mystic `+1`?):
Gamertag2 = Gamertag2.Replace("^", "");
Problem
I am trying to remove all of a specific character from a string. I have been using `String.Replace`, but it does nothing, and I don't know why. This is my current code: ``` if (Gamertag2.Contains("^")) { Gamertag2.Replace("^" + 1, ""); } ``` This just leaves the string as it was before. Can anyone please explain to me as to why?