AppendLine不添加一些字符串一个新的生产线

AppendLine不添加一些字符串一个新的生产线

本文介绍了为什么StringBuilder.AppendLine不添加一些字符串一个新的生产线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用StringBuilder的创建字符串的主体文本(而不是HTML)的电子邮件中使用。然而,一些线(其中,i包括动态数据,一个新的线未添加,但在一些换行按预期方式工作。

I'm trying to use stringbuilder to create a body of string to be used in a text (not HTML) email. However some lines (where i include dynamic data, a new line is not added, but in some the newline works as intended.

有一些基本的东西我使用StringBuilder类还是有一些应该发生更根本的进程的时候失踪了?

Is there something basic i'm missing when using the stringbuilder class or is there some more fundamental process that should be happening?

在跌破code:

sbUser.AppendLine("Please find below confirmation of your registration details. If any of these details are incorrect, please email [email protected]");
sbUser.AppendLine();
sbUser.AppendLine("Selected event : " + ContentPage.FetchByID(int.Parse(ddlEvent.SelectedValue)).PageTitle);
sbUser.AppendLine("Date of event : " + thisEvent.EventStartDate.ToString("dd MMM yyyy"));
sbUser.AppendLine("==============================================================");
sbUser.AppendLine();

(ContentPage和thisEvent使用亚音速(V2)自定义类建。的PageTitle是字符串的输出型)

(ContentPage and thisEvent are custom classes built using Subsonic(v2). PageTitle is an output type of string)

是获得此为输出:

    Please find below confirmation of your registration details. If any of these details are incorrect, please email [email protected]

Selected event : My Event Date of event : 16 Sept 2012 ==============================================================

你可以看到,在code中的3号线后一切都使一切去到一行。

as you can see, everything after the 3rd line in the code makes everything go on to one line.

不过,再往下code我使用:

however, further down the code i use:

sbRR.AppendLine("First name : " + txtFirstname.Text.Trim());
sbRR.AppendLine("Surname : " + txtSurname.Text.Trim());
etc,

和正确所有这些出现在单独的线路。我不明白为什么会这样。

and all these appear on seperate lines correctly. I can't see why this is happening.

电子邮件是由这样

mailMessage.Body = sbUser.ToString()+ sbRR.ToString();

添加以下code:

sbUser.AppendLine("Selected event : " + ContentPage.FetchByID(int.Parse(ddlEvent.SelectedValue)).PageTitle + Environment.NewLine);
sbUser.AppendLine("Date of event : " + thisEvent.EventStartDate.ToString("dd MMM yyyy") + Environment.NewLine);

产生以下输出:

produces the following output:

Selected event : My Event

Date of event : 16 Sept 2012

==============================================================

这工作我想,除了它的加入2换行符(AppendLine和Environment.NewLine)。似乎从数据库中提取的数据直接直入一个StringBuilder似乎与该行结束搞乱。即使我的数据库拉后添加文本,但仍停留在一行。

which works i suppose, except it's added 2 newlines (the AppendLine and the Environment.NewLine). it seems that pulling the data directly straight from the database into a stringbuilder seems to be messing with the line ending. Even if I add text after the database pull, it still stays on one line.

更新

StringBuilder.Append(嗒嗒+ Environment.NewLine)产生正确的结果,但我仍然不理解为什么工程和 .AppendLine(嗒嗒+<数据库内容>)。不起作用。

doingStringBuilder.Append("blah"+Environment.NewLine)produces the correct result, however i'm still not understanding why that works and .AppendLine("blah"+<database content>) doesn't work.

推荐答案

sbUser.AppendLine();

尝试使用

sbUser.Append(Environment.NewLine);

不知道为什么这个工程...

No idea why this works...

这篇关于为什么StringBuilder.AppendLine不添加一些字符串一个新的生产线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 14:13