[英]remove the '\' character from a string
I want to remove the '\\'
character from my strings. 我想从字符串中删除'\\'
字符。
I've tried several ways but I am still not having any luck 我已经尝试了几种方法,但是我仍然没有运气
Here is a small piece of my code. 这是我的一小段代码。 It is in fact an HTML obtained from another site. 实际上,它是从另一个站点获得的HTML。
I'm going to use it at my own site but \\ makes problems! 我将在自己的网站上使用它,但是\\会造成问题!
src=\"http://bartarinha.com/file/logo/ideal.jpg\" style=\"border: 0px none\">
This code gives me error: 这段代码给我错误:
news_body_html = news_body_html.Replace("\", " ");
What is the correct way to remove the character? 删除字符的正确方法是什么?
try news_body_html.Replace("\\\\", " "); 尝试news_body_html.Replace(“ \\\\”,“”);
or news_body_html.Replace(@"\\", " "); 或news_body_html.Replace(@“ \\”,“”);
Have a go with 一起去
news_body_html = news_body_html.Replace("\\", " ");
EDIT: 编辑:
Actually try this: 其实试试这个:
news_body_html = news_body_html.Replace('\\', ' ');
Note that I'm using single quotes here around the slashes. 请注意,我在斜杠周围使用单引号。 I forgot that Replace expects a char as the parameter. 我忘记了Replace期望使用char作为参数。
您必须转义转义字符:
news_body_html = news_body_html.Replace("\\", " ");
news_body_html = news_body_html.Replace("\\", " ");
That will remove the \\ from your code. 这将从代码中删除\\。 the \\ is a control used most commonly for \\n to make a new line, so it was seeing it as a command with nothing to do, therefore doing nothing with it. \\是最常用于\\ n换行的控件,因此它将\\ n视为与该命令无关的命令,因此不执行任何操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.