473,796 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StringBuilder

Hello,

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

StringBuilder body = new StringBuilder() ;
body.AppendForm at("{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.AppendForm at("{0},<br/><br/>", userName);
body.AppendLine ("How are you?");

or maybe some other way?

Thanks,

Miguel
Nov 6 '08 #1
3 11770
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.AppendForm at("{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.New Line
character.

Pete
Nov 7 '08 #2
On Nov 7, 12:59*am, "Peter Duniho" <NpOeStPe...@nn owslpianmk.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.AppendForm at("{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.New Line *
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.AppendForm at("{0},\n\n", userName);

instead of:
body.AppendForm at("{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
On Thu, 06 Nov 2008 17:22:51 -0800, shapper <md*****@gmail. comwrote:
>AppendLine() should be fine, or you can append the Environment.New Line Â*
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.AppendForm at("{0},\n\n", userName);

instead of:
body.AppendForm at("{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.New Line or to simply call StringBuilder.A ppendLine(). Both of
which I already mentioned.

Pete
Nov 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
4722
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie, 20-30k), what are the performance differences (if any with something as trivial as this) between initializing a new instance of StringBuilder with a specified capacity vs. initializing a new instance without... (the final length is not fixed) ie,
20
1899
by: Alvin Bruney | last post by:
On the advice of a user, I've timed stringbuilder v string. Here are the results. Here are the numbers: Total # queries 3747 Time in Milliseconds StringBuilder: String 460.6624 320.4608 350.504 220.3168
0
8776
by: Mo | last post by:
I am having problem with marshaling struct in C#. //the original C++ struct typedef struct _tagHHP_DECODE_MSG { DWORD dwStructSize; // Size of decode structure. TCHAR pchMessage; // decoded message data TCHAR chCodeID; // AIM Id of symbology TCHAR chSymLetter; // HHP Id of symbology
11
18268
by: deko | last post by:
I need to loop through a string and remove all characters except numbers or letters. I am getting an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the size of the collection" Not sure what is going on... any suggestions welcome! public static string fixStr(string aStr) { StringBuilder bStr = new StringBuilder(aStr.Length); for (int i = 0; i < aStr.Length; i++)
2
7393
by: Peter | last post by:
Hi, A newbie question .. I want to use an array of length 4 while each array element is a string of 40 chars. I typed .. StringBuilder title = new StringBuilder(40);
9
9161
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new functionality of VB.NET.
12
2717
by: Richard Lewis Haggard | last post by:
I thought that the whole point of StringBuilder was that it was supposed to be a faster way of building strings than string. However, I just put together a simple little application to do a comparative analysis between the two and, surprisingly, string seems to out perform StringBuilder by a significant amount. A string concatenation takes not quite twice as long using StringBuilder than it does with a string. This doesn't sound right to...
2
1686
by: m00nm0nkey | last post by:
Ok well i thought i'd try a different approach, so what I'm now trying is appending 50,000 lines from the collection to a stringbuilder, and then writing that entire stringbuilder to a file. However, look at this log: 21/04/2006 14:09:06: Building String Start 21/04/2006 14:09:14: appended 10,000 lines to the stringbuilder 21/04/2006 14:09:39: appended 10,000 lines to the stringbuilder 21/04/2006 14:10:20: appended 10,000 lines to the...
5
4377
by: pantagruel | last post by:
Hi, It is generally stated that stringbuilder should be used instead of just concatenating strings with the plus operator. That's fine enough what I'm wondering in cases I have: String S = "hello" + World; Does it make any sense to use Stringbuilder in a case like the above,
34
3561
by: raylopez99 | last post by:
StringBuilder better and faster than string for adding many strings. Look at the below. It's amazing how much faster StringBuilder is than string. The last loop below is telling: for adding 200000 strings of 8 char each, string took over 25 minutes while StringBuilder took 40 milliseconds! Can anybody explain such a radical difference?
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.