How to eliminate ALL line breaks in string?

后端 未结 12 1965
傲寒
傲寒 2021-01-30 10:22

I have a need to get rid of all line breaks that appear in my strings (coming from db). I do it using code below:

value.Replace(\"\\r\\n\", \"\").Replace(\"\\n\"         


        
12条回答
  •  萌比男神i
    2021-01-30 11:16

    This is my first attempt at this, but I think this will do what you want....

    var controlChars = from c in value.ToCharArray() where Char.IsControl(c) select c;
    foreach (char c in controlChars)  
       value = value.Replace(c.ToString(), "");
    

    Also, see this link for details on other methods you can use: Char Methods

提交回复
热议问题