How to remove new line characters from a string?

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

    I like to use regular expressions. In this case you could do:

    string replacement = Regex.Replace(s, @"\t|\n|\r", "");
    

    Regular expressions aren't as popular in the .NET world as they are in the dynamic languages, but they provide a lot of power to manipulate strings.

提交回复
热议问题