如何为回车添加char13和char 10? [英] How do I add char13 and char 10 for carriage return?

查看:227
本文介绍了如何为回车添加char13和char 10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的一个数据中添加回车符,以便在导出excel中的数据时显示为换行符。

目前我得到的原始数据有'br'标签在里面。我想用char(13)+ char(10)替换br标签进行换行。



情况:

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

推荐答案

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



这看起来像是C#,但你的斜杠是不正确的。它应该是:


This looks to be C# but your slash is incorrect. It should be:

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



参考: C#转义序列 [ ^ ]



但你的其余代码是VB。所以它应该是:


reference: C# Escape Sequences[^]

But the rest of your code is VB. So it should be:

.Replace("<br>", vbCrLf))



参考: Constants.vbCrLf Field(Microsoft.VisualBasic) [ ^ ]


这篇关于如何为回车添加char13和char 10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆