Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C“替换字符串”;与';_C#_String - Fatal编程技术网

C# C“替换字符串”;与';

C# C“替换字符串”;与';,c#,string,C#,String,我有这根绳子 string b = IIF("L" = "H", 9.0, IIF("L" = "M", 7.5, 6.0)) 我想用'H'替换“H”,用'L'替换“L” 我试过这个,但不起作用: b = b.Replace("\"", "'"); 它给了我这个错误: SyntaxError:在参数列表之后缺少) 这很有效 string b = "IIF(\"L\" = \"H\", 9.0, IIF(\"L\" = \"M\", 7.5, 6.0)";

我有这根绳子

string b = IIF("L" = "H", 9.0, IIF("L" = "M", 7.5, 6.0))
我想用
'H'
替换
“H”
,用
'L'
替换
“L”

我试过这个,但不起作用:

b = b.Replace("\"", "'");
它给了我这个错误:

SyntaxError:在参数列表之后缺少)

这很有效

            string b = "IIF(\"L\" = \"H\", 9.0, IIF(\"L\" = \"M\", 7.5, 6.0)";
            b = b.Replace("\"", "'");

在.Net提琴()中玩这个:


我相信你需要在Replace函数中转义
。你能从源文件中粘贴更多行吗?你写的句子应该有用,你的字符串赋值甚至不会编译。请使用C#中的真实代码.IIF?我错过了什么吗?哈哈,我以为那是他正在处理的字符串的内容,但也许他实际上是在用c#中的那个句子。。。
using System;

public class Program
{
    public static void Main()
    {
        var test = "This is \"a\" string";

        Console.WriteLine(test);

        test = test.Replace('\"', '\'');

        Console.WriteLine(test);
    }
}