VB.NET ASP.NET StringBuilder Source Code Example


Putting
the Pieces of .NET Together - 8 Part Video Series | ||||
| Introduction | ||||
| Videos 1-4 | 1. Servers (3 minutes) | 2. .NET Framework (10 minutes) | 3. Security (8 minutes) | 4. Monitoring Tools (10 minutes) |
| Videos 5-8 | 5. Web Servers (6 minutes) | 6. SQL Server (6 minutes) | 7. Software Develop Tools (10 minutes) | 8. Languages (2 minutes) |
| Download PDF | Putting the Pieces of .NET Together - 48-page PDF | |||
VB.NET ASP.NET StringBuilder Source Code Example
Purpose: – Illustrates using StringBuilder and StringBuilder Methods in VB.NET 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 Visual Basic for Language
- name of Web Site could be VBNET_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.vb
- 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 | | ? |
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="StringBuilder.aspx.vb" Inherits="LanguageBasics_StringBuilder" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title></title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<div> |
<asp:Label ID="Label1a" runat="server" Text="Label"></asp:Label><br /> |
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br /> |
<asp:Label ID="Label2a" runat="server" Text="Label"></asp:Label><br /> |
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label><br /><br /> |
<asp:Label ID="Label3a" runat="server" Text="Label"></asp:Label><br /> |
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label><br /><br /> |
<asp:Label ID="Label4a" runat="server" Text="Label"></asp:Label><br /> |
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label><br /><br /> |
<asp:Label ID="Label5a" runat="server" Text="Label"></asp:Label><br /> |
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label><br /><br /> |
</div> |
</form> |
</body> |
</html> |
Step 2: Click on Copy Code to Cut-n-paste code into StringBuilder.aspx.vb
| Visual Basic | | copy code | | ? |
Imports System.Text |
Imports System |
Imports System.Text.StringBuilder |
Partial Class LanguageBasics_StringBuilder |
Inherits System.Web.UI.Page |
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
'**************************************************************************************** |
' Example #1: StringBuilder Append(string) - most common way stringbuilder is used |
' Adds the specified string or string representation of the specified value to the end |
' of the string |
'**************************************************************************************** |
Dim sb As New StringBuilder |
Label1a.Text = "Example #1: Simple StringBuilder Append(string) " |
sb.Append("First Line") |
sb.Append("<br />") |
sb.Append("Second Line") |
Label1.Text = sb.ToString() |
'Append(string, startIndex, count) |
'**************************************************************************************** |
' Example #2: StringBuilder Append(string, startIndex, count) |
' Adds a substring of the specified string, starting with the specified |
' position and having the specified length, to the end of the string |
'**************************************************************************************** |
Dim sb2 As New StringBuilder |
Label2a.Text = "Example #2: StringBuilder Append(string, startIndex, count)" |
sb2.Append("The dog and cat ") |
sb2.Append("love to fight and play", 0, 13) 'take love to fight and add to end of prev string |
Label2.Text = sb2.ToString() |
'Insert(index, string[, count]) |
'**************************************************************************************** |
' Example #3: StringBuilder Insert(index, string[, count]) |
' Inserts the specified string or a string representation of the specified |
' value at the specified position in the string the specified number of |
' times. If the count is ommitted, a single copy of the string is inserted. |
'**************************************************************************************** |
Dim sb3 As New StringBuilder |
Label3a.Text = "Example #3: Insert(index, string[, count])" |
sb3.Append("This is the initial sentence") |
sb3.Insert(20, "and modified ", 2) |
Label3.Text = sb3.ToString() |
'Remove(startIndex,count) |
'**************************************************************************************** |
' Example #4: StringBuilder Remove(startIndex,count) |
' Removes the specified number of characters from the string starting at |
' the specified position |
'**************************************************************************************** |
Dim sb4 As New StringBuilder |
Label4a.Text = "Example #4: StringBuilder Remove(startIndex,count)" |
sb4.Append("This is the initial sentence") |
sb4.Remove(20, 8) |
Label4.Text = sb4.ToString() |
'Replace(oldString,newString [,startIndex][,count]) |
'**************************************************************************************** |
' Example #5: StringBuilder Replace(oldString,newString [,startIndex][,count]) |
' Replaces all occurences of the old string with the new string starting |
' at the specified position and continuing for the specified number of characters. |
' If you omit startIndex, it starts at beginning |
' If you omit count, it does entire string |
'**************************************************************************************** |
Dim sb5 As New StringBuilder |
Label5a.Text = "Example #5: StringBuilder Replace(oldString,newString [,startIndex][,count])" |
sb5.Append("This is the initial sentence") |
sb5.Replace("initial", "new") |
Label5.Text = sb5.ToString() |
End Sub |
End Class |
Step 3: Click on Copy Code to Cut-n-paste code into web.config right after the appSettings section
| XML | | copy code | | ? |
<connectionStrings> |
<add name="Northwind_ConnectionString" |
connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI" /> |
<add name="Pubs_ConnectionString" |
connectionString="Server=(local)\SQLEXPRESS;Initial Catalog=pubs;Integrated Security=SSPI" /> |
</connectionStrings> |
Related posts:
- C# ASP.NET StringBuilder Source Code Example C# ASP.NET StringBuilder Source Code Example...
- VB.NET StringBuilder Source Code Example VB.NET StringBuilder Source Code Example...
- C# StringBuilder Source Code Example C# StringBuilder Source Code Example...
- VB.NET ASP.NET String.Format DateTime Source Code Example VB.NET ASP.NET String.Format DateTime Source Code Example...
- C# ASP.NET String.Format DateTime Source Code Example C# ASP.NET String.Format DateTime Source Code Example...
Related posts brought to you by Yet Another Related Posts Plugin.
