Click here to Skip to main content
15,888,908 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I currently have a multiline textbox on my web application page.

The information entered into the multiline textbox is saved to a database field.

For reporting i create a CSV file but i have noticed there is a problem, when users enter data into the textbox its creating a carriage return/line break when creating the CSV.

How can i remove this carriage return/linebreak when creating my csv file from a string?
Posted
Comments
[no name] 5-Jun-14 8:55am    
Replace("\n", "")

The below statement replaces line breaks with a space character.

C#
sValueWithLineBreaks.Replace(Environment.NewLine, " ");


Hope it helps.
 
Share this answer
 
You can use Regex also.
C#
var oldString = "your\ttext area\n string\r\n for testing";
var newString = string.Join(" ", Regex.Split(oldString, @"(?:\r\n|\n|\r)"));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900