How to remove new line characters from a string?

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

    If speed and low memory usage are important, do something like this:

    var sb = new StringBuilder(s.Length);
    
    foreach (char i in s)
        if (i != '\n' && i != '\r' && i != '\t')
            sb.Append(i);
    
    s = sb.ToString();
    

提交回复
热议问题