StringBuilder的 [英] StringBuilder

查看:74
本文介绍了StringBuilder的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我正在创建一个邮件正文使用

StringBuilder:


StringBuilder body = new StringBuilder();

body.AppendFormat(" {0},",userName);

body.AppendLine();

body.AppendLine();

body.AppendLine(你好吗?);


我应该如何创建空行?用户使用各种ApendLine作为之前的例子,或者使用< br />:


StringBuilder body = new StringBuilder();

body.AppendFormat(" {0},< br />< br />",userName);

body.AppendLine("你好吗? );


或者其他一些方式?


谢谢,


Miguel

Hello,

I am creating the body of a mail message to be sent using
StringBuilder:

StringBuilder body = new StringBuilder();
body.AppendFormat("{0},", userName);
body.AppendLine();
body.AppendLine();
body.AppendLine("How are you?");

How should I create empty lines? User various ApendLine as n the
previous example or maybe using <br />:

StringBuilder body = new StringBuilder();
body.AppendFormat("{0},<br/><br/>", userName);
body.AppendLine("How are you?");

or maybe some other way?

Thanks,

Miguel

推荐答案

2008年11月6日星期四15:11:09 -0800,shapper< md ***** @ gmail.comwrote:
On Thu, 06 Nov 2008 15:11:09 -0800, shapper <md*****@gmail.comwrote:

[...]

我应该如何创建空行?用户使用各种ApendLine作为之前的例子,或者使用< br />:


StringBuilder body = new StringBuilder();

body.AppendFormat(" {0},< br />< br />",userName);

body.AppendLine("你好吗? ");
[...]
How should I create empty lines? User various ApendLine as n the
previous example or maybe using <br />:

StringBuilder body = new StringBuilder();
body.AppendFormat("{0},<br/><br/>", userName);
body.AppendLine("How are you?");



我不明白上面的例子。 .NET没有做任何特殊的事情
带有HTML元素的
。所以附加< br />没有在你的字符串中插入换行符



AppendLine()应该没问题,或者你可以附加Environment.NewLine

字符。


Pete

I don''t understand the above example. .NET doesn''t do anything special
with HTML elements. So appending "<br/>" doesn''t insert line-breaks into
your string.

AppendLine() should be fine, or you can append the Environment.NewLine
character.

Pete


11月7日,12:59 * am,Peter Duniho < NpOeStPe ... @nnowslpianmk.com>

写道:
On Nov 7, 12:59*am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:

2008年11月6日星期四15:11:09 -0800 ,shapper< mdmo ... @ gmail.comwrote:
On Thu, 06 Nov 2008 15:11:09 -0800, shapper <mdmo...@gmail.comwrote:

[...]

我应该如何创建空行?用户使用各种ApendLine作为前一个例子的

或者使用< br />:
[...]
How should I create empty lines? User various ApendLine as n the
previous example or maybe using <br />:


* * StringBuilder body = new StringBuilder();

* * body.AppendFormat(" {0},< br />< br />",userName);

* * body.AppendLine(你好吗?);
* * StringBuilder body = new StringBuilder();
* * body.AppendFormat("{0},<br/><br/>", userName);
* * body.AppendLine("How are you?");



我不明白上面的例子。 * .NET没有做任何特殊的事情*
带有HTML元素的
。 *所以附加< br />没有在*

中插入换行符。


AppendLine()应该没问题,或者你可以附加Environment.NewLine *

字符。


Pete


I don''t understand the above example. *.NET doesn''t do anything special*
with HTML elements. *So appending "<br/>" doesn''t insert line-breaks into *
your string.

AppendLine() should be fine, or you can append the Environment.NewLine *
character.

Pete



但如果我发送电子邮件Html格式赢了''我通过在我的字符串中使用< br /来获得换行符



基本上,最后我做:myMail.Body = body.ToString();


我也读过以下内容:
http://www.systemnetmail.com/faq/4.8.aspx


所以我认为我有两个选择:

1.创建一个包含电子邮件正文的HTML页面并发送它...

我认为这对于复杂的邮件正文更有用,例如

新闻通讯。

2.使用StringBuilder创建电子邮件正文,并将所需的

HTML标记包含为< p>,< br />等...


如果我发送否我可以使用的Html格式电子邮件:

body.AppendFormat(" {0},\ n \ n",userName);


而不是:

body.AppendFormat(" {0},< br />< br />",userName);


或不是吗?

只是想找到创建Html邮件正文的正确方法

邮件和非Html邮件消息。

谢谢,

Miguel

But if I am sending the email Html format won''t I get the line breaks
by using <br/in my string?
Basically, at the end I do: myMail.Body = body.ToString();

I''ve also read the following:
http://www.systemnetmail.com/faq/4.8.aspx

So I think I have two options:
1. Create an HTML page that contains the email body and send it ...
I think this would be more useful for complex mail bodies like
Newsletters.
2. Use StringBuilder to create the email body and include the needed
HTML tags as <p>, <br/>, etc ...

And if I send a No Html format email I could use:
body.AppendFormat("{0},\n\n", userName);

instead of:
body.AppendFormat("{0},<br/><br/>", userName);

Or not?

Just trying to find the correct way to create the body of Html mail
messages and Non Html mail messages.

Thanks,
Miguel


2008年11月6日星期四17:22:51 -0800,shapper < md ***** @ gmail.comwrote:
On Thu, 06 Nov 2008 17:22:51 -0800, shapper <md*****@gmail.comwrote:

> AppendLine()应该没问题,或者你可以追加Environment.NewLine?*
性格。
>AppendLine() should be fine, or you can append the Environment.NewLine ?*
character.



但是,如果我发送电子邮件Html格式,我不会通过使用< br /在我的行中断行

串?


But if I am sending the email Html format won''t I get the line breaks
by using <br/in my string?



否。您将获得一些HTML显示引擎将呈现为换行符的文本。有一个很大的区别,特别是因为在HTML中,实际的

换行符_don''t_渲染为换行符(它们被认为是白色空间

并且是忽略)。

No. You''ll get some text that an HTML display engine will render as
line-breaks. There''s a big difference, especially since in HTML, actual
line-breaks _don''t_ render as line-breaks (they are considered white-space
and are ignored).


基本上,最后我做:myMail.Body = body.ToString();


我还阅读了以下内容:
http:// www。 systemnetmail.com/faq/4.8.aspx


所以我认为我有两个选择:

1.创建一个包含发送电子邮件正文并发送...

我认为这对于复杂的邮件正文更有用,例如

简报。

2.使用StringBuilder创建电子邮件正文并包含所需的

HTML标记为< p>,< br />等等...
Basically, at the end I do: myMail.Body = body.ToString();

I''ve also read the following:
http://www.systemnetmail.com/faq/4.8.aspx

So I think I have two options:
1. Create an HTML page that contains the email body and send it ...
I think this would be more useful for complex mail bodies like
Newsletters.
2. Use StringBuilder to create the email body and include the needed
HTML tags as <p>, <br/>, etc ...



如果您尝试发送HTML格式的电子邮件,则应使用HTML

代码进行换行。如何生成它们并不重要,只要

你最终得到你想要的格式。

If you are trying to send HTML-formatted email, then you should use HTML
codes for line-breaks. How you generate them is unimportant, as long as
you ultimately get the formatting you want.


如果我发送一个No Html格式我可以使用的电子邮件:

body.AppendFormat(" {0},\ n \ n",userName);


而不是:

body.AppendFormat(" {0},< br />< br />",userName);


或不是?
And if I send a No Html format email I could use:
body.AppendFormat("{0},\n\n", userName);

instead of:
body.AppendFormat("{0},<br/><br/>", userName);

Or not?



您绝对不希望在

非HTML电子邮件中使用HTML代码进行换行。是否''\\ n''是适当的换行符

取决于您的收件人,但它可能会有效。对于

纯文本,非HTML电子邮件,规范的.NET方法是使用

Environment.NewLine或简单地调用StringBuilder.AppendLine()。我已经提到了




Pete

You definitely would not want to use HTML codes for line-breaks in
non-HTML email. Whether ''\n'' is the appropriate line-break character
depends a bit on your recipient, but it would probably work. For
plain-text, non-HTML email, the canonical .NET method is to use
Environment.NewLine or to simply call StringBuilder.AppendLine(). Both of
which I already mentioned.

Pete


这篇关于StringBuilder的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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