Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace string with double quotes

Tags:

c#

I want to replace, from a JSON file :"[" to :["

The below runs but without delivering the expected.Any clues?(I looked in similar questions, but I was more confused)

string contenty = contentx.Replace(":"["",":["");
return contentx;
like image 443
Proffesore Avatar asked Jun 29 '26 21:06

Proffesore


2 Answers

You're returning contentx instead of contenty. contenty is the variable that has the new string.

like image 78
itsme86 Avatar answered Jul 02 '26 09:07

itsme86


First you have to escape the double quotes with \"

Then you have to return the "return value" of the expression in the same variable, or simply use one return statement:

return contentx.Replace(":\"[\"", ":[\"");
like image 35
iMad Avatar answered Jul 02 '26 09:07

iMad



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!