Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string Replace not working in asp.net [duplicate]

Tags:

c#

replace

string mystring="the are boys";

string[] tags = {"the"};

string[] replace ={"they"}

mystring.Replace(tags[0],replace[0]) // is not working

mystring.Replace("the","they") // is working 

I thought both are same but first statement is not working. The second one is. Please help me to solve the problem.

like image 846
Kishore Chowdary Avatar asked Jan 25 '26 01:01

Kishore Chowdary


1 Answers

I assume that you don't assign the return value of String.Replace to the variable. But since strings are immutable you have to do that:

mystring = mystring.Replace(tags[0],replace[0])
like image 158
Tim Schmelter Avatar answered Jan 27 '26 16:01

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!