By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

StringBuilder

P: n/a
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
Nov 6 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Thu, 06 Nov 2008 15:11:09 -0800, shapper <md*****@gmail.comwrote:
[...]
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?");
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
Nov 7 '08 #2

P: n/a
On Nov 7, 12:59*am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Thu, 06 Nov 2008 15:11:09 -0800, shapper <mdmo...@gmail.comwrote:
[...]
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?");

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
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

Nov 7 '08 #3

P: n/a
On Thu, 06 Nov 2008 17:22:51 -0800, shapper <md*****@gmail.comwrote:
>AppendLine() should be fine, or you can append the Environment.NewLine *
character.

But if I am sending the email Html format won't I get the line breaks
by using <br/in my string?
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).
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 ...
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.
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?
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
Nov 7 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.