How to remove new line characters from a string?

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

    Well... I would like you to understand more specific areas of space. \t is actually assorted as a horizontal space, not a vertical space. (test out inserting \t in Notepad)

    If you use Java, simply use \v. See the reference below.

    \h - A horizontal whitespace character:

    [\t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000]

    \v - A vertical whitespace character:

    [\n\x0B\f\r\x85\u2028\u2029]

    But I am aware that you use .NET. So my answer to replacing every vertical space is..

    string replacement = Regex.Replace(s, @"[\n\u000B\u000C\r\u0085\u2028\u2029]", "");
    

提交回复
热议问题