Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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# - Fatal编程技术网

C# 从字符串中剥离字符

C# 从字符串中剥离字符,c#,C#,我有一个向web应用程序发送POST请求并解析响应的代码 我正在发送带有以下代码的请求: byte[]responseBytes=webClient.UploadValues(“,”POST“,formData) 使用以下命令将字节数据转换为字符串: string responsefromserver = Encoding.UTF8.GetString(responseBytes); responsefromserver等于这样的内容:“abcd” 我想去掉“字符。因此,我使用以下方法: Co

我有一个向web应用程序发送POST请求并解析响应的代码

我正在发送带有以下代码的请求:

byte[]responseBytes=webClient.UploadValues(“,”POST“,formData)

使用以下命令将
字节
数据转换为
字符串

string responsefromserver = Encoding.UTF8.GetString(responseBytes);
responsefromserver
等于这样的内容:
“abcd”

我想去掉
字符。因此,我使用以下方法:

Console.WriteLine(responsefromserver.Replace('"', ''));
但是
'
向我显示了这个错误:
空字符文本

当我尝试使用
string.Empty
而不是
'
时,我遇到了以下错误:
参数2:无法从“string”转换为“char”

如何从字符串中删除
字符?

没有,因此您需要使用
字符串的重载。替换为接受两个参数的
字符串

您需要对双引号进行转义,因此应该是:

Replace("\"", "");
或:

没有,因此您需要使用
String.Replace的重载,该重载接受两个参数的
String

您需要对双引号进行转义,因此应该是:

Replace("\"", "");
或:

您有一些选择:

responsefromserver.Replace("\"", "");//escaping the "

responsefromserver.Replace('"', '\0'); //null symbol <- not reccomended, only to allow you to use the char overload. It will NOT remove the " but replace with a null symbol!
responsefromserver.Replace('"', (char)0); // same as above in another format
您有一些选择:

responsefromserver.Replace("\"", "");//escaping the "

responsefromserver.Replace('"', '\0'); //null symbol <- not reccomended, only to allow you to use the char overload. It will NOT remove the " but replace with a null symbol!
responsefromserver.Replace('"', (char)0); // same as above in another format

使用
responsefromserver.Replace(“\”,string.Empty)
。使用
responsefromserver.Replace(“\”,string.Empty)
Replace
的一个重载接受
Char
,但要使用Replace替换字符串,需要使用第二个重载,它需要一个字符串作为第一个参数。编辑您的答案以改进它,似乎不值得创建得到相同解决方案的新答案。干杯。@CamiloTerevinto谢谢,从来没有注意到重载
Replace
的一个重载接受一个
Char
,但是要用字符串替换来使用Replace,您需要使用第二个重载,它需要一个字符串作为第一个参数。编辑您的答案以改进它,似乎不值得创造一个新的答案,得出相同的解决方案。干杯。@Camiloterivento谢谢你,从来没有注意到超载