从字符串C#中删除'\'char [英] Remove '\' char from string c#

查看:59
本文介绍了从字符串C#中删除'\'char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码

string line = ""; 

while ((line = stringReader.ReadLine()) != null)
{
    // split the lines
    for (int c = 0; c < line.Length; c++)
    {
        if ( line[c] == ',' && line[c - 1] == '"' && line[c + 1] == '"')
        {
            line.Trim(new char[] {'\\'}); // <------
            lineBreakOne = line.Substring(1, c  - 2);
            lineBreakTwo = line.Substring(c + 2, line.Length - 2);
        }
    }
}

我已添加评论网到我想知道的那条线上。我想从字符串中删除所有 \字符。这是正确的方法吗?我不工作。

I have added a comment net to the line I am wondering about. I want to remove all '\' chars from the string. Is this the correct way to to this? I doesnt work. All \ are still in the string.

推荐答案

您可以使用:

line.Replace(@"\", "");

line.Replace(@"\", string.Empty);

这篇关于从字符串C#中删除'\'char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆