C# ASP.NET String Examples – String Examples ASP.NET C#

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

  1. HTML
  2. CSS
  3. Classic ASP
  4. .NET (included in ASP section)
  5. AJAX
  6. Silverlight (in Microsoft Section)
  7. SharePoint (in Microsoft Section)
  8. Web Design
  9. Blogging
  10. SEO
  11. and much more
You can learn more about Lynda.com by watching the 5-minute video at About Lynda.com. If you are only focusing on .NET, you are missing out on the "big picture" and on many of the underlying fundamentals! To be an Ideal Programmer, you need to have the largest knowledge base possible.

JavaScript tutorials



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.

  

DiscountASP .NET hosting  JavaScript tutorials


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

C# ASP.NET String Examples – String Examples ASP.NET C#

Purpose: – Illustrates using and in C-Sharp ASP.NET.

Prerequistes:

  1. Install Visual Web Developer 2008
  2. Install SQL Server Express
  3. Download Northwind and Pubs Databases
  4. Attach Northwind Database to Databases in Sql Express
  5. 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:

  1. Use Visual Web Developer 2008
  2. 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.
  3. Add New folder named "LanguageBasics"
    • Right-click project name in solution explorer;
    • add new folder;
    • name of folder could be: LanguageBasics
  4. Add Web Form Named String 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 String
  5. Click on copy code in code below to copy code into web form String.aspx
  6. Click on copy code in second set of code below to copy code into code-behind String.aspx.cs
  7. Right-click on String.aspx in solution explorer and select view in browser

Step 1: Click on Copy Code to Cut-n-paste code into String.aspx

 XML |  copy code |? 
01
02
< %@ Page Language="C#" AutoEventWireup="true" CodeFile="String.aspx.cs" Inherits="LanguageBasics_String" %>
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><br />
14
        <asp :Label ID="Label1" runat="server" Text="Label"></asp><br /><br />
15
        <asp :Label ID="Label2a" runat="server" Text="Label"></asp><br />
16
        <asp :Label ID="Label2" runat="server" Text="Label"></asp><br /><br />
17
        <asp :Label ID="Label3a" runat="server" Text="Label"></asp><br />
18
        <asp :Label ID="Label3" runat="server" Text="Label"></asp><br /><br />
19
        <asp :Label ID="Label4a" runat="server" Text="Label"></asp><br />
20
        <asp :Label ID="Label4" runat="server" Text="Label"></asp><br /><br />
21
        <asp :Label ID="Label5a" runat="server" Text="Label"></asp><br />
22
        <asp :Label ID="Label5" runat="server" Text="Label"></asp><br /><br />
23
 
24
         <asp :Label ID="Label6a" runat="server" Text="Label"></asp><br />
25
        <asp :Label ID="Label6" runat="server" Text="Label"></asp><br /><br />
26
        <asp :Label ID="Label7a" runat="server" Text="Label"></asp><br />
27
        <asp :Label ID="Label7" runat="server" Text="Label"></asp><br /><br />
28
        <asp :Label ID="Label8a" runat="server" Text="Label"></asp><br />
29
        <asp :Label ID="Label8" runat="server" Text="Label"></asp><br /><br />
30
        <asp :Label ID="Label9a" runat="server" Text="Label"></asp><br />
31
        <asp :Label ID="Label9" runat="server" Text="Label"></asp><br /><br />
32
        <asp :Label ID="Label10a" runat="server" Text="Label"></asp><br />
33
        <asp :Label ID="Label10" runat="server" Text="Label"></asp><br /><br />
34
 
35
        <asp :Label ID="Label11a" runat="server" Text="Label"></asp><br />
36
        <asp :Label ID="Label11" runat="server" Text="Label"></asp><br /><br />
37
        <asp :Label ID="Label12a" runat="server" Text="Label"></asp><br />
38
        <asp :Label ID="Label12" runat="server" Text="Label"></asp><br /><br />
39
        <asp :Label ID="Label13a" runat="server" Text="Label"></asp><br />
40
        <asp :Label ID="Label13" runat="server" Text="Label"></asp><br /><br />
41
        <asp :Label ID="Label14a" runat="server" Text="Label"></asp><br />
42
        <asp :Label ID="Label14" runat="server" Text="Label"></asp><br /><br />
43
 
44
    </div>
45
    </form>
46
</body>
47
</html>
48
 
49


Step 2: Click on Copy Code to Cut-n-paste code into SqlCommandUpdate.aspx.cs
  |  copy code |? 
001
002
 
003
partial class LanguageBasics_String : System.Web.UI.Page
004
{
005
 
006
    protected void Page_Load(object sender, System.EventArgs e)
007
    {
008
 
009
        //****************************************************************************************
010
        // Example #1: StartsWith(string)
011
        // Example #2: EndsWith(string)
012
        // Example #3: IndexOf(string[, startIndex][,count])
013
        // Example #4: LastIndexOf(string[, startIndex][,count])
014
        // Example #5: Insert(startIndex, string)
015
        // Example #6: PadLeft(totalWidth [, paddingCharacter])
016
        // Example #7: PadRight(totalWidth [, paddingCharacter])
017
        // Example #8: Remove(startIndex, count)
018
        // Example #9: Replace(oldString, newString)
019
        // Example #10: Substring(startIndex[, length])
020
        // Example #11: ToLower
021
        // Example #12: ToUpper
022
        // Example #13: Trim
023
        // Example #14: Length
024
        //****************************************************************************************
025
 
026
 
027
        //****************************************************************************************
028
        // Example #1: StartsWith(string)
029
        // Returns a Boolean value that indicates if the string starts with the specified string. 
030
        //****************************************************************************************
031
 
032
        Label1a.Text = "Example #1: StartsWith(string) ";
033
 
034
        string strStartsWithExample = "This is a test string";
035
 
036
        Label1.Text = strStartsWithExample.StartsWith("This").ToString();
037
        //Returns True
038
 
039
 
040
 
041
        //****************************************************************************************
042
        // Example #2: EndsWith(string)
043
        // Returns a Boolean value that indicates if the string ends with the specified string. 
044
        //****************************************************************************************
045
 
046
        Label2a.Text = "Example #2: EndsWith(string) ";
047
 
048
        string strEndsWithExample = "This is a test string";
049
 
050
        Label2.Text = strEndsWithExample.EndsWith("string").ToString();
051
        //Returns True
052
 
053
 
054
 
055
        //****************************************************************************************
056
        // Example #3: IndexOf(string[, startIndex][,count])
057
        // Returns an integer that represents the position of the first occurrence of the
058
        // specified number of characters. If you specify startIndex, that specifies
059
        // where to start looking. If you specify count, that specifies how many characters to 
060
        // to search past start. If the string is not found, this method returns -1
061
        //****************************************************************************************
062
 
063
        Label3a.Text = "Example #3: IndexOf(string[, startIndex][,count]) ";
064
 
065
        string strIndexOfExample = "This is a test string";
066
 
067
        Label3.Text = strIndexOfExample.IndexOf("is").ToString();
068
        //Returns 2
069
 
070
 
071
 
072
 
073
        //****************************************************************************************
074
        // Example #4: LastIndexOf(string[, startIndex][,count])
075
        // Returns an integer that represents the position of the last occurrence of the
076
        // specified number of characters. If you specify startIndex, that specifies
077
        // where to start looking. If you specify count, that specifies how many characters to 
078
        // to search past start. If the string is not found, this method returns -1
079
        //****************************************************************************************
080
 
081
        Label4a.Text = "Example #4: LastIndexOf(string[, startIndex][,count]) ";
082
 
083
        string strLastIndexOfExample = "This is a test string";
084
 
085
        Label4.Text = strLastIndexOfExample.LastIndexOf("is").ToString();
086
        //Returns 5
087
 
088
 
089
 
090
        //****************************************************************************************
091
        // Example #5: Insert(startIndex, string)
092
        // Returns a string with the specified string inserted beginning at the specified position.
093
        //****************************************************************************************
094
 
095
        Label5a.Text = "Example #5: Insert(startIndex, string) ";
096
 
097
        string strInsertExample = "This is a test string";
098
        int intIndex = 0;
099
 
100
        // First find position of word test
101
        intIndex = strInsertExample.IndexOf("test");
102
 
103
        // Insert "simple" before "test"
104
        Label5.Text = strInsertExample.Insert(intIndex, "simple ");
105
 
106
 
107
 
108
        //****************************************************************************************
109
        // Example #6: PadLeft(totalWidth [, paddingCharacter])
110
        // Returns a string that is right-aligned and padded on left with character specified.
111
        // If no padddingCharacter is specified, space is used. totalWidth is total width of column
112
        // This allows you to create a nice straight column even though lengths of text vary.
113
        //****************************************************************************************
114
 
115
        Label6a.Text = "Example #6: PadLeft(totalWidth [, paddingCharacter]) ";
116
 
117
        string strPadLeftExampleA = "This is a test string";
118
 
119
 
120
 
121
        // PadLeft "simple" before "test"
122
        Label6.Text = strPadLeftExampleA.PadLeft(35);
123
 
124
 
125
 
126
        //****************************************************************************************
127
        // Example #7: PadRight(totalWidth [, paddingCharacter])
128
        // Returns a string that is left-aligned and padded on right with character specified.
129
        // If no padddingCharacter is specified, space is used. totalWidth is total width of column
130
        // This allows you to create a nice straight column even though lengths of text vary.
131
        //****************************************************************************************
132
 
133
        Label7a.Text = "Example #7: PadRight(totalWidth [, paddingCharacter]) ";
134
 
135
        string strPadRightExampleA = "This is a test string";
136
 
137
 
138
 
139
 
140
        // PadRight "simple" before "test"
141
        Label7.Text = strPadRightExampleA.PadRight(35) + "next column starts here";
142
 
143
 
144
 
145
 
146
 
147
        //****************************************************************************************
148
        // Example #8: Remove(startIndex, count)
149
        // Returns a string with the specified number of characters removed starting at startIndex.
150
        // If no Count is specified, the remainder of string is removed
151
        //****************************************************************************************
152
 
153
        Label8a.Text = "Example #8: Remove(startIndex, count) ";
154
 
155
        string strRemoveExample = "This is a test string";
156
        int intIndexRemove = 0;
157
 
158
        // First find position of word test
159
        intIndexRemove = strRemoveExample.IndexOf("test");
160
 
161
        // Remove rest of string starting with word "test"
162
        Label8.Text = strRemoveExample.Remove(intIndex);
163
 
164
 
165
 
166
        //****************************************************************************************
167
        // Example #9: Replace(oldString, newString)
168
        // Returns a string with all occurences of oldString replaced by newString
169
        //****************************************************************************************
170
 
171
        Label9a.Text = "Example #9: Replace(oldString, newString) ";
172
 
173
        string strReplaceExample = "This is a test string";
174
 
175
        // Replace "This" with "That"
176
        Label9.Text = strReplaceExample.Replace("This", "That");
177
 
178
 
179
 
180
        //****************************************************************************************
181
        // Example #10: Substring(startIndex[, length])
182
        // Returns the string that starts at the specified position and has the specified
183
        // length. If the length is not specified, all of the characters to the end are returned.
184
        //****************************************************************************************
185
 
186
        Label10a.Text = "Example #10: Substring(startIndex[, length]) ";
187
 
188
        string strSubstringExample = "This is a test string";
189
        int intIndexSubstring = 0;
190
 
191
        // First find position of word test
192
        intIndexSubstring = strRemoveExample.IndexOf("test");
193
 
194
        // Get everything starting at "test" to end of string
195
        Label10.Text = strSubstringExample.Substring(intIndexSubstring);
196
 
197
 
198
 
199
        //****************************************************************************************
200
        // Example #11: ToLower
201
        // Returns the string in Lowercase
202
        //****************************************************************************************
203
 
204
        Label11a.Text = "Example #11: ToLower";
205
 
206
        string strToLowerExample = "This is a test string";
207
 
208
        // Return Lowercase
209
        Label11.Text = strToLowerExample.ToLower().ToString();
210
 
211
 
212
        //****************************************************************************************
213
        // Example #12: ToUpper
214
        // Returns the string in Uppercase
215
        //****************************************************************************************
216
 
217
        Label12a.Text = "Example #12: ToUpper ";
218
 
219
        string strToUpperExample = "This is a test string";
220
 
221
        // Return Uppercase
222
        Label12.Text = strToUpperExample.ToUpper().ToString();
223
 
224
 
225
 
226
        //****************************************************************************************
227
        // Example #13: Trim
228
        // Returns the string with leading and trailing spaces removed
229
        //****************************************************************************************
230
 
231
        Label13a.Text = "Example #13: Trim ";
232
 
233
        string strTrimExample = "     ABC     ";
234
 
235
        // Return Uppercase
236
        Label13.Text = strTrimExample.Trim().Length.ToString();
237
 
238
 
239
        //****************************************************************************************
240
        // Example #14: Length
241
        // Returns the string with leading and trailing spaces removed
242
        //****************************************************************************************
243
 
244
        Label14a.Text = "Example #14: Length ";
245
 
246
        string strLengthExample = "     ABC     ";
247
 
248
        // Return Uppercase
249
        Label14.Text = strLengthExample.Length.ToString();
250
 
251
 
252
 
253
 
254
    }
255
}
256
 
257
 
258
 
259
 
260


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:

  1. VB.NET ASP.NET String Examples – String Examples ASP.NET VB.NET VB.NET ASP.NET String Examples - String Examples ASP.NET VB.NET...
  2. C# ASP.NET StringBuilder Source Code Example C# ASP.NET StringBuilder Source Code Example...
  3. C# String Examples – String Examples C# C# String Examples - String Examples C#...
  4. VB.NET ASP.NET StringBuilder Source Code Example VB.NET ASP.NET StringBuilder Source Code Example...
  5. VB.NET String – String VB.NET VB.NET String - String VB.NET ...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

This blog uses the cross-linker plugin developed by Web-Developers.Net