IMG-LOGO

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

andy - 24 Jul, 2013 3168 Views 0 Comment

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.

Related Articles

How to remove html tags from string in c#?

Sometimes you need to remove HTML tags from string to ensure there are no dangerous or malicious scripts especially when you want to store the string or data text into the database.