Skip to main content
Aug 24, 2013
/// <summary>
/// Method replaces br tag in passed text with new lines
/// </summary>
/// <param name="text">string text for replacing</param>
/// <returns>string represents text with replaced br tag</returns>
public string ReplaceBRWithNewline(string text)
{
  string newText = "";
 
  // Check for empty string.
  if (string.IsNullOrEmpty(text))
  {
    return string.Empty;
  }
 
  // Create regular expressions
  System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"(<br />|<br/>|</ br>|</br>)");
 
  // Replace new line with <br/> tag
  newText = regex.Replace(text, "\r\n");
 
  // Result
  return newText;
}