How to remove new line characters from a string?

后端 未结 11 977
时光取名叫无心
时光取名叫无心 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:23

    A LINQ approach:

    string s = "This is a Test String.\n   This is a next line.\t This is a tab.\n'";
    
    string s1 = String.Join("", s.Where(c => c != '\n' && c != '\r' && c != '\t'));
    

提交回复
热议问题