C# ASP.NET StringBuilder Source Code Example
"I tried to learn .NET by taking boot camp classes that cost me $6,000. After taking the classes, I discovered tons of free (and very cheap) videos on the internet created by experts in the field. I found the videos to be much better than the classrooms. The videos were presented by Microsoft presenters that knew the material backwards and forwards, and they were much cheaper and better than the classroom teachers. I have spent the last three years organizing and hunting down the videos for my own use and decided that all could benefit by sharing what I found." - Wade Harvey
Click Here for Free 24 hour pass to lynda.com.
I AM VERY EXCITED ABOUT THIS AMAZING NEW DISCOVERY
Over 40,000 Top-Notch Video Tutorials (or 3,452 hours) on Lynda.com
I had stumbled across Lynda.com many times before, but never stopped to try it out. I recently took the plunge and started using Lynda.com to help me improve my javascript skills (See Javascript Essential Training 2007 by Dori Smith). It has revolutionized my understanding of the language! I love the fact that the exercise files allow you to follow along in real time with what the instructor is saying. Learning by doing is an extremely powerful technique. I have to give the site an A+ for both quality and content.
I am planning on using Lynda Videos to help me improve in:

Looking for premium .NET Training Videos? The best premium .NET Videos that I have found are at Learn Visual Studio. Those videos are only about 50 cents per hour, as compared to $25 per hour that other sites charge!
LearnVisualStudio is currently having a 25% off sale ($50 savings) and giving away a free membership to TrainingSpot ($60 value) when LVS Lifetime Membership is purchased.


Limited Time Offer: Free Lifetime Membership to Progress Monitor ($24.95 value) when you purchase any membership at Learn Visual Studio, Lynda Videos or any hosting account at DiscountASP - just forward order confirmation to harvey007@sbcglobal.net
I had stumbled across Lynda.com many times before, but never stopped to try it out. I recently took the plunge and started using Lynda.com to help me improve my javascript skills (See Javascript Essential Training 2007 by Dori Smith). It has revolutionized my understanding of the language! I love the fact that the exercise files allow you to follow along in real time with what the instructor is saying. Learning by doing is an extremely powerful technique. I have to give the site an A+ for both quality and content.
I am planning on using Lynda Videos to help me improve in:
- HTML
- CSS
- Classic ASP
- .NET (included in ASP section)
- AJAX
- Silverlight (in Microsoft Section)
- SharePoint (in Microsoft Section)
- Web Design
- Blogging
- SEO
- and much more

Looking for premium .NET Training Videos? The best premium .NET Videos that I have found are at Learn Visual Studio. Those videos are only about 50 cents per hour, as compared to $25 per hour that other sites charge!
LearnVisualStudio is currently having a 25% off sale ($50 savings) and giving away a free membership to TrainingSpot ($60 value) when LVS Lifetime Membership is purchased.


Limited Time Offer: Free Lifetime Membership to Progress Monitor ($24.95 value) when you purchase any membership at Learn Visual Studio, Lynda Videos or any hosting account at DiscountASP - just forward order confirmation to harvey007@sbcglobal.net
StringBuilder Source Code Example
Purpose: – Illustrates using StringBuilder and StringBuilder Methods in C-Sharp ASP.NET.
Prerequistes:
- Install Visual Web Developer 2008
- Install SQL Server Express
- Download Northwind and Pubs Databases
- Attach Northwind Database to Databases in Sql Express
- Attach pubs Database to Databases in Sql Express
Notes:
- You can build your own library of syntax examples by using same web site over and over and just add new web forms to it.
Instructions:
- Use Visual Web Developer 2008
- Create new web site;
- Click File/New Web Site
- Select ASP.NET Website Template
- Select C-Sharp for Language
- name of Web Site could be CSharp_ASPNET_Syntax.
- Add New folder named "LanguageBasics"
- Right-click project name in solution explorer;
- add new folder;
- name of folder could be: LanguageBasics
- Add Web Form Named StringBuilder to LanguageBasics folder
- Right-click LanguageBasics folder;
- add new item;
- Select Web Form
- Check place code behind in separate file
- Web Form name could be StringBuilder
- Click on copy code in code below to copy code into web form StringBuilder.aspx
- Click on copy code in second set of code below to copy code into code-behind StringBuilder.aspx.cs
- Right-click on StringBuilder.aspx in solution explorer and select view in browser
Step 1: Click on Copy Code to Cut-n-paste code into StringBuilder.aspx
| XML | | copy code | | ? |
| 01 | |
| 02 | <%@ Page Language="C#" AutoEventWireup="true" CodeFile="StringBuilder.aspx.cs" Inherits="LanguageBasics_StringBuilder" %> |
| 03 | |
| 04 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 05 | |
| 06 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 07 | <head id="Head1" runat="server"> |
| 08 | <title></title> |
| 09 | </head> |
| 10 | <body> |
| 11 | <form id="form1" runat="server"> |
| 12 | <div> |
| 13 | <asp:Label ID="Label1a" runat="server" Text="Label"></asp:Label><br /> |
| 14 | <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br /> |
| 15 | <asp:Label ID="Label2a" runat="server" Text="Label"></asp:Label><br /> |
| 16 | <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br /><br /> |
| 17 | <asp:Label ID="Label3a" runat="server" Text="Label"></asp:Label><br /> |
| 18 | <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br /><br /> |
| 19 | <asp:Label ID="Label4a" runat="server" Text="Label"></asp:Label><br /> |
| 20 | <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br /><br /> |
| 21 | <asp:Label ID="Label5a" runat="server" Text="Label"></asp:Label><br /> |
| 22 | <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br /><br /> |
| 23 | |
| 24 | </div> |
| 25 | </form> |
| 26 | </body> |
| 27 | </html> |
| 28 | |
| 29 |
Step 2: Click on Copy Code to Cut-n-paste code into SqlCommandUpdate.aspx.cs
| | | copy code | | ? |
| 001 | |
| 002 | using System.Text; |
| 003 | using System; |
| 004 | |
| 005 | partial class LanguageBasics_StringBuilder : System.Web.UI.Page |
| 006 | { |
| 007 | |
| 008 | |
| 009 | protected void Page_Load(object sender, System.EventArgs e) |
| 010 | { |
| 011 | |
| 012 | |
| 013 | //**************************************************************************************** |
| 014 | // Example #1: StringBuilder Append(string) - most common way stringbuilder is used |
| 015 | // Adds the specified string or string representation of the specified value to the end |
| 016 | // of the string |
| 017 | //**************************************************************************************** |
| 018 | |
| 019 | |
| 020 | StringBuilder sb = new StringBuilder(); |
| 021 | |
| 022 | Label1a.Text = "Example #1: Simple StringBuilder Append(string) "; |
| 023 | sb.Append("First Line"); |
| 024 | sb.Append("<br />"); |
| 025 | sb.Append("Second Line"); |
| 026 | |
| 027 | Label1.Text = sb.ToString(); |
| 028 | |
| 029 | |
| 030 | //Append(string, startIndex, count) |
| 031 | //**************************************************************************************** |
| 032 | // Example #2: StringBuilder Append(string, startIndex, count) |
| 033 | // Adds a substring of the specified string, starting with the specified |
| 034 | // position and having the specified length, to the end of the string |
| 035 | //**************************************************************************************** |
| 036 | |
| 037 | |
| 038 | StringBuilder sb2 = new StringBuilder(); |
| 039 | Label2a.Text = "Example #2: StringBuilder Append(string, startIndex, count)"; |
| 040 | sb2.Append("The dog and cat "); |
| 041 | sb2.Append("love to fight and play", 0, 13); |
| 042 | //take love to fight and add to end of prev string |
| 043 | Label2.Text = sb2.ToString(); |
| 044 | |
| 045 | |
| 046 | |
| 047 | //Insert(index, string[, count]) |
| 048 | //**************************************************************************************** |
| 049 | // Example #3: StringBuilder Insert(index, string[, count]) |
| 050 | // Inserts the specified string or a string representation of the specified |
| 051 | // value at the specified position in the string the specified number of |
| 052 | // times. If the count is ommitted, a single copy of the string is inserted. |
| 053 | //**************************************************************************************** |
| 054 | |
| 055 | |
| 056 | StringBuilder sb3 = new StringBuilder(); |
| 057 | Label3a.Text = "Example #3: Insert(index, string[, count])"; |
| 058 | |
| 059 | sb3.Append("This is the initial sentence"); |
| 060 | sb3.Insert(20, "and modified ", 2); |
| 061 | Label3.Text = sb3.ToString(); |
| 062 | |
| 063 | |
| 064 | |
| 065 | //Remove(startIndex,count) |
| 066 | //**************************************************************************************** |
| 067 | // Example #4: StringBuilder Remove(startIndex,count) |
| 068 | // Removes the specified number of characters from the string starting at |
| 069 | // the specified position |
| 070 | //**************************************************************************************** |
| 071 | |
| 072 | |
| 073 | StringBuilder sb4 = new StringBuilder(); |
| 074 | Label4a.Text = "Example #4: StringBuilder Remove(startIndex,count)"; |
| 075 | |
| 076 | sb4.Append("This is the initial sentence"); |
| 077 | sb4.Remove(20, 8); |
| 078 | Label4.Text = sb4.ToString(); |
| 079 | |
| 080 | |
| 081 | |
| 082 | //Replace(oldString,newString [,startIndex][,count]) |
| 083 | //**************************************************************************************** |
| 084 | // Example #5: StringBuilder Replace(oldString,newString [,startIndex][,count]) |
| 085 | // Replaces all occurences of the old string with the new string starting |
| 086 | // at the specified position and continuing for the specified number of characters. |
| 087 | // If you omit startIndex, it starts at beginning |
| 088 | // If you omit count, it does entire string |
| 089 | //**************************************************************************************** |
| 090 | |
| 091 | StringBuilder sb5 = new StringBuilder(); |
| 092 | Label5a.Text = "Example #5: StringBuilder Replace(oldString,newString [,startIndex][,count])"; |
| 093 | |
| 094 | |
| 095 | sb5.Append("This is the initial sentence"); |
| 096 | sb5.Replace("initial", "new"); |
| 097 | Label5.Text = sb5.ToString(); |
| 098 | |
| 099 | |
| 100 | |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 |
Step 3: Click on Copy Code to Cut-n-paste code into web.config right after the appSettings section
| XML | | copy code | | ? |
| 1 | |
| 2 | <connectionStrings> |
| 3 | <add name="Northwind_ConnectionString" |
| 4 | connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI" /> |
| 5 | <add name="Pubs_ConnectionString" |
| 6 | connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=pubs;Integrated Security=SSPI" /> |
| 7 | </connectionStrings> |
| 8 | |
| 9 |
Related posts:
- VB.NET ASP.NET StringBuilder Source Code Example VB.NET ASP.NET StringBuilder Source Code Example...
- C# StringBuilder Source Code Example C# StringBuilder Source Code Example...
- VB.NET StringBuilder Source Code Example VB.NET StringBuilder Source Code Example...
- C# ASP.NET String.Format DateTime Source Code Example C# ASP.NET String.Format DateTime Source Code Example...
- VB.NET ASP.NET String.Format DateTime Source Code Example VB.NET ASP.NET String.Format DateTime Source Code Example...
Related posts brought to you by Yet Another Related Posts Plugin.
