skinnyWill
skinnyWill

Reputation: 277

Trying to remove a hyphen from string . The replace method is not working

I have a

string myStringTitle= "Insurance Subsequent Action - Removing Coverage";

I use the method

myStringTitle.replace("-", "");

and also

Regex.Replace(myStringTitle, @"[^-]", ""); <br>

none of them seems to work any reason why?. thanks

Upvotes: 0

Views: 2481

Answers (1)

Farhad Jabiyev
Farhad Jabiyev

Reputation: 26655

Strings are immutable. Replace() will create a new string and you must assign the result to a variable. It does not modify the string in-place.

So, change your code as:

myStringTitle = myStringTitle.Replace("-", "");

Upvotes: 6

Related Questions