Published on: 24 Jul, 2013

How to replace line break in string using ASP.Net C#?

Tumblr Digg Google Plus

When you have a multi-line textbox that allows users to enter sentences, they might have entered some line breaks. Those line breaks need to be replaced with break line in HTML. In this tutorial, you will learn a quick function to replace them.

In C#, there are particulars symbols and function represent these line breaks. You can easily copy below function that will accet a string value and will replace all line breaks found in the string.

public static string ReplaceNewLine(string str) {
	str = str.Replace("\\r\\n", "");
	str = str.Replace(Environment.NewLine, "");
	return str;
}

Comments

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.