Reputation: 412
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;
Upvotes: 2
Views: 559
Reputation: 346
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(":\"[\"", ":[\"");
Upvotes: 1
Reputation: 1396
Try it like this (you have some issues with the double quotes in a string):
return contentx.Replace(@":""[""", @":[""");
Another option is:
return contentx.Replace(":\"[\"", ":[\"");
This will make sure that the character escaping goes well and your string is replaced properly. Moreover, as Equalsk showed in his comment, this will also solve the problem of returning the wrong variable and creating an unnecessary variable.
Upvotes: 0
Reputation: 19496
You're returning contentx
instead of contenty
. contenty
is the variable that has the new string.
Upvotes: 9