相关疑难解决方法(0)

为什么StringBuilder.AppendLine不添加带有一些字符串的新行?

我正在尝试使用stringbuilder来创建一个字符串体,用于文本(而不是HTML)电子邮件.但是有些行(我包含动态数据,不添加新行,但在某些行中,换行符按预期工作).

在使用stringbuilder类时是否存在基本的缺失或是否存在应该发生的更基本的过程?

在下面的代码中:

sbUser.AppendLine("Please find below confirmation of your registration details. If any of these details are incorrect, please email someone@somewhere.com");
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();
Run Code Online (Sandbox Code Playgroud)

(ContentPage和thisEvent是使用Subsonic(v2)构建的自定义类.PageTitle是字符串的输出类型)

将此作为输出:

    Please find below confirmation of your registration details. If any of these details are incorrect, please email someone@somewhere.com

Selected event : My Event Date of event : 16 Sept 2012 ==============================================================
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,代码中第3行之后的所有内容都会使所有内容都转到一行.

但是,我使用的代码更进一步:

sbRR.AppendLine("First name : " + txtFirstname.Text.Trim()); …
Run Code Online (Sandbox Code Playgroud)

.net c# stringbuilder newline

31
推荐指数
3
解决办法
6万
查看次数

标签 统计

.net ×1

c# ×1

newline ×1

stringbuilder ×1