Wednesday, 29 May 2013

How to use StringBuilder class and accessing in different-2 property of that class using c#

How to use StringBuilder object and accessing in different-2 property of that object using c#



Step 1 : First create your website in asp.net and create one .aspx page .

Step2  : Open .aspx page source code .cs file



Step 3: First add one import class file to access StringBuilder class

using System.Text;
 
Step 3 : Create one object of StringBuilder class

StringBuilder str = new StringBuilder();


Step 4 : Access different-2 property of StringBuilder object.

StringBuilder str = new StringBuilder();

// append test in stringbuilder
str.Append("My name is Anuj Rohila");

 // print string builder content
Response.Write("<br/>String : " + str.ToString());

// count the length of string
Response.Write("<br/>Length : " + str.Length);

 // append symbol  str.Append("=-=-=-",1,2)
Response.Write("<br/>String : " + str.Append("=-=-=-", 1, 2));

 // remove symbol  str.Remove(1,5)
Response.Write("<br/>String : " + str.Remove(1, 5));

// insert test  str.Insert(1,"Test",2)
Response.Write("<br/>String : " + str.Insert(1,"Test",2));

 // Replace test  str.Replace("Anuj", "David")
Response.Write("<br/>String : " + str.Replace("Anuj", "David"));



Step 5: Also access more property and do more change as per you.

Output will be:

String : My name is Anuj Rohila
Length : 22
String : My name is Anuj Rohila-=
String : Me is Anuj Rohila-=
String : MTestTeste is Anuj Rohila-=
String : MTestTeste is David Rohila-





No comments:

Post a Comment

Thank you for your interest .