Search code examples
c#formatsubstringformat-string

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


I have a string like this:

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

But I need to create a string like this:

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

How can I accomplish this?


Solution

  • This should work:

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