0

I would like to remove "{ and replace it with {. The following is the line of code that I'm currently using.

var MyString = DataString.Replace(@""{", "");

The following is the error message I'm getting enter image description here

Please advise

Thanks

1
  • I believe this is not just any string but a Json response from somewhere. So it this really what you want? Or it is just a quick fix Commented Aug 24, 2019 at 18:12

2 Answers 2

1

You need to escape the quote that you want to replace using two quotes, so for your example:

    var MyString = DataString.Replace(@"""{", "{");

Also see How to include quotes in a string for alternatives to use quotes in strings.

Sign up to request clarification or add additional context in comments.

Comments

1

If you are expecting JSON data then what you really need is a JSON Parser for that. And if you just want to replace "{ to { then you simply need to escape and replace the string like below:

// Suppose the variable named str has a value of Hello"{ wrapped in double quotes
var strReplaced = str.Replace("\"{", "{");
Console.WriteLine($"strReplaced: {strReplaced}");
// This will result in strReplaced: Hello{

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.