473,805 Members | 2,007 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 11771
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
4724
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
8777
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
9162
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
2718
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
1687
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
3562
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
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10103
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
9179
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...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
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
3
3006
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.