Posted By

dotNetkow on 01/25/11


Tagged

String c#


Versions (?)

Remove carriage return, newline, and spaces from string


 / Published in: C#
 

Useful for detecting when a string is really empty.

  1. string result = "
  2. \n\n \r \n\n";
  3. result = result.TrimEnd('\r', '\n', ' ');
  4. // result = ""

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: creiglee on July 23, 2015

You can remove spaces and new line from a string in the following ways..

Regex.Replace(str, @"\t\n\r", "");

Or

str = str.Replace(System.Environment.NewLine, ",");

Or

str = str.Replace(vbLf, [String].Empty) str = str.Replace(vbCr, [String].Empty) str = str.Replace(vbTab, [String].Empty)

Full Source: http://net-informations.com/q/faq/newline.html

Lee

You need to login to post a comment.