Fur*_*han 26 .net c# string insert
我正在编写ac#代码,我从数据库中获取值并使用它.我面临的问题如下.
如果我从数据库中获取的值是:
string cat1 = "sotheby's";
Run Code Online (Sandbox Code Playgroud)
现在使用这个猫我想在单引号之前插入一个转义字符,为实现这一点,我写了下面的代码:
string cat1 = "sotheby's";
if (cat1.Contains("'")) {
var indexofquote = cat1.IndexOf("'");
cat1.Insert(indexofquote-1,"\");
var cat2 = cat1;
}
Run Code Online (Sandbox Code Playgroud)
插入行中的错误上升,反斜杠(转义字符).错误是常量中的新行.请帮我解决这个错误.