Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to get a line break to store in a database.

I am using a listbox to add items each item should be printed on a new line. eg

Modify existing software.
Design and develop software systems.
Resolve customer problems.


however its printing

Modify existing software.Design and develop software systems.Resolve customer problems.


What I have tried:

string duties = "";
            foreach (ListItem item in LBDuties.Items)
            {
                duties = duties + item + System.Environment.NewLine;

            }
            Response.Write(duties);
Posted
Updated 19-May-17 4:16am
Comments
[no name] 19-May-17 10:14am    
Web pages do not know what NewLine is. They know what <BR> is however.
Member 9331278 19-May-17 10:33am    
I am more concern about how its stored in the database.

I want it to be stored with line breaks

1 solution

New line is an ASCII thing, when you are creating HTML it does not obey ASCII new lines, you need HTML new lines (<br/>)

Response.Write(duties.Replace("\r\n", "<br/>"));


Also use a StringBuilder rather than string concatination.
 
Share this answer
 
Comments
Member 9331278 19-May-17 11:09am    
I am more concern about how its stored in the database.

I want it with the newline.
F-ES Sitecore 19-May-17 11:16am    
An ASCII newline or an HTML new line? They are two different things and not interchangeable. In general it is recommended you store your data with an ASCII new line (\r\n) and convert it to an HTML new line when you display it, as that makes data management easier.

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