Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to add carriage return in one of my data so that i could display as line break when i export the data in excel.
Currently the raw data i am getting has 'br' tag in it. I want to replace the br tag with char(13)+ char(10) for line break.

Situation:
we have data in one of a table which has  tag to break line while rendering the data in web. 
for example: 
Day 		| ToDoList
------------ ----------------------------------
Sunday      | Wake up at 8am  Visit Parents
------------ ----------------------------------
Monday      | Wake up at 7am  Go to Work
------------ ----------------------------------

I need to get the data from that table and need to load in another table for another application, which also render
the data in browser. But this application export this data in excel file as well. 
I do not want  tag between data in my new table and excel file but i do want line break. 

Day         | ToDoList
------------ ----------------------------------
Sunday      | Wake up at 8am 
            | Visit Parents
------------ ----------------------------------
Monday      | Wake up at 7am 
            | Go to Work
------------ ----------------------------------


How do i achieve this.

What I have tried:

My code:
<pre>This is what i have tried but it did not work. 

#1 
If Not String.IsNullOrWhiteSpace(row("ToDoList").ToString) Then
		cmd.Parameters.AddWithValue("@pToDoList", (row("ToDoList").ToString).Replace("", vbCrLf))
Else

#2
If Not String.IsNullOrWhiteSpace(row("ToDoList").ToString) Then
	cmd.Parameters.AddWithValue("@pToDoList", (row("ToDoList").ToString).Replace("", Environment.NewLine))
Else

#3
If Not String.IsNullOrWhiteSpace(row("ToDoList").ToString) Then
	 cmd.Parameters.AddWithValue("@pToDoList", (row("ToDoList").ToString).Replace("", "+Char(13)+char(10)"))
Else
Posted
Updated 30-Aug-17 6:18am
v3
Comments
RedDk 30-Aug-17 18:49pm    
I've toyed with this problem in ssmse for over a decade now and have never come up with a satisfactory solution. Do the work in Excel. Don't waste another minute of your time in ssmse (which also includes weeks of time ad infinitum trolling google for lingering doubts about this decision).

1 solution

.Replace("<br>", "/n/r"))

This looks to be C# but your slash is incorrect. It should be:
C#
.Replace("<br>", "\n\r"))

reference: C# Escape Sequences[^]

But the rest of your code is VB. So it should be:
C#
.Replace("<br>", vbCrLf))

reference: Constants.vbCrLf Field (Microsoft.VisualBasic)[^]
 
Share this answer
 
Comments
[no name] 30-Aug-17 9:10am    
Thank you. But it did not break the line in Database as well as when I export the data in excel.
Graeme_Grant 30-Aug-17 10:13am    
I can't see what you mean so I can't comment. However, the solution does exactly what you asked it to do.
[no name] 30-Aug-17 11:44am    
It does not break the line when I stored the data in database or after I exported the data in excel.
[no name] 30-Aug-17 11:46am    
this is what I want to achieve. Currently the raw data i am getting has 'br' tag in it. I want to replace the 'br' tag with char(13)+ char(10) for line break.
Graeme_Grant 30-Aug-17 18:18pm    
Done in solution above.

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