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

Red Virus
  • 1,633
  • 3
  • 25
  • 34
  • 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 – Bosco Aug 24 '19 at 18:12

2 Answers2

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.

user7217806
  • 2,014
  • 2
  • 10
  • 12
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{
Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42