How to remove new line characters from a string?

后端 未结 11 981
时光取名叫无心
时光取名叫无心 2020-11-27 10:32

I have a string in the following format

string s = \"This is a Test String.\\n   This is a next line.\\t This is a tab.\\n\'

I want to remo

11条回答
  •  时光说笑
    2020-11-27 11:17

    FYI,

    Trim() does that already.

    The following LINQPad sample:

    void Main()
    {
        var s = " \rsdsdsdsd\nsadasdasd\r\n ";
        s.Length.Dump();
        s.Trim().Length.Dump();
    }
    

    Outputs:

    23
    18
    

提交回复
热议问题