C# 如何去除字符串中多余的字符?

How to remove extra characters in a string in c#?

我有这样的字符串:

"\"Data Source=.; Initial Catalog=dbname; user Id=sa;Password=1;Integrated Security=false\""

但我需要创建一个这样的字符串:

"Data Source=.; Initial Catalog=dbname; user Id=sa;Password=1;Integrated Security=false"

我怎样才能做到这一点?

将“\”\“”替换为 \”。

myString.Replace("\"\"", "\"")

这应该有效:

string myOriginalString = "\"Whatever\"";
MySubString = mystring.Substring(1, mystring.Length - 2);