-2

I am trying to handle both double and single quote in my code behind , but none of them are working. Below is my code

private String _systemPath;

public String SystemPath
{
    get {

       // return _systemPath = _systemPath.Replace("'", "\'").Replace("\"", @"\\\""); 
       return  _systemPath = _systemPath.Replace("'", @"\'").Replace(@"\""", "\"");

    }
    set { _systemPath = value; }
}

any help will be appreciated.

4

1 回答 1

-2

如果您想\在每个单引号或双引号之前添加一个,那么您确实很接近:

_systemPath.Replace("'", @"\'").Replace("\"", @"\""");

你所拥有的是相反的;您正在将所有转义双引号更改为非转义双引号。

于 2012-12-10T19:37:15.657 回答