← Tutti gli articoli

Remove Blank Lines in a textbox

18 June 2013  ·  C# · Recipe  ·  33 visite

Remove Blank Lines in a textbox

  1. private   string  removeBlankLines(String text)  
  2. {  
  3.     // Remove all tabs characters  
  4.     String retText = text.Replace("\t"" ");  
  5.   
  6.     // If the first one or more lines are blank, remove them  
  7.     retText = Regex.Replace(retText, "(?<Text>.*)(?:(^\u0020*\r\n)(\u0020*\r\n\u0020*)*)""${Text}");  
  8.   
  9.     // Replace all occurrences of muliple new lines to single newlines  
  10.     retText = Regex.Replace(retText, "(?<Text>.*)(?:(\u0020*\r\n\u0020*){2,})""${Text}\r\n");  
  11.   
  12.     // Remove any trailing new lines or white space  
  13.     retText = Regex.Replace(retText, "(?<Text>.*)(?:(\u0020*\r\n)(\u0020*\r\n\u0020*)*$)""${Text}");  
  14.   
  15.     return retText;  
  16. }  
Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.