SlideShare a Scribd company logo
1 of 10
Strings in C#
Dr. Neeraj Kumar Pandey
Strings in C#
 In C# System.String class is used to manipulate strings.
 System.String is a very powerful and versatile class, but it is not by
any means the only string-related class in the .NET armory.
 System.Text and System.Text.RegularExpression namespaces are
also used in Building Strings,Formatting Expressions and Regular
Expression
Dr. Neeraj Kumar
Pandey
Immutable Strings
 In this type of strings, we cannot modify the characters of a string.
Dr. Neeraj Kumar
Pandey
Immutable Strings
Dr. Neeraj Kumar
Pandey
Comparing Strings
Compare() Method
int n=string.Compare(s1,s2);
 Zero interger, if s1 is equal to s2
 A positive Integer (1) , if s1 is greater than s2
 A negative integer(-1), if s1 is less than s2
Equals() Method
There are two versions of Equals method. They are implemented as follows:-
bool b1= s2.Equals(s1);
bool b2= string.Equals(s2,s1);
These methods returns a Boolean value true if s1 and s2 are equal, otherwise false.
The == Operator
bool b3= (s1==s2); //b3 is true if they are equal
We very often use such statements in decision statements, like:-
if(s1==s2)
Dr. Neeraj Kumar
Pandey
Mutable Strings
 This type of strings are modifiable using the StringBuilder class.
StringBuilder str1=new StringBuilder(“hello”);
StringBuilder str2=new StringBuilder();
 They can grow dynamically as more characters are added to them.
 They can grow either unbounded or up to a configurable maximum.
 Mutable Strings are also known as dynamic strings.
Dr. Neeraj Kumar
Pandey
Mutable Strings(Contd..)
 The System.Text namespace contains the class StringBuilder,
therefore we must include the using System.Text directive for
creating and manipulating mutable strings.
Dr. Neeraj Kumar
Pandey
Mutable String Program
using System;
using System.Text;
class strbuild
{
public static void Main()
{
string str1,str2;
Console.WriteLine("Enter first string");
str1=Console.ReadLine();
Console.WriteLine("Enter Second string");
str2=Console.ReadLine();
StringBuilder s1 = new StringBuilder(str1);
StringBuilder s2 = new StringBuilder(str2);
//1.Appending a String
s1.Append("Smile");
// Console.WriteLine("String After Append :" +s1);
//2.Append Format
s2.AppendFormat("1)s2 after Append Format {0}",s2);
s1.AppendFormat("2)s1 after Append Format {0}",s1);
//3.Ensure Capacity
int x=s1.EnsureCapacity(30);
//4.Inserting a String
s2.Insert(3,"Life");
//5.Remove
s1.Remove(5,3);
//6.Replace
s2.Replace('A', '*');
//7.Capacity
int y= s1.Capacity;
Console.WriteLine("Capacity is"+y);
s1.Capacity=100;
y=s1.Capacity;
Console.WriteLine("New Capacity is"+y);
//8.Length
int z = s1.Length;
int v = s2.Length;
Console.WriteLine(" Length of s1 "+ z);
Console.WriteLine("Length of s2"+ v);
//9.MaxCapacity
int c= s1.MaxCapacity;
Console.WriteLine("Max Capacity"+s1);
//10.setting a character
int n=s2.Length;
s2[n-1]='@';
}
}
Dr. Neeraj Kumar
Pandey
Regular Expression
 A regular expression may be applied to a text to accomplish tasks
such as :-
 To locate substring and return them
 To modify one or more substrings and return them
 To identify substrings that begins with or end with a pattern of
characters.
 To find all the words that begin with a group of characters and end
with some other characters
 To find all the occurrences of a substring pattern.
 System.Text.RegualrExpressions supports a number of classes that
can be used for searching, matching and modifying a text
document.The important classes are:-
 Regex, MathCollection, Match.
Dr. Neeraj Kumar
Pandey
Regular Expression Program
using System;
using System.Text;
using System.Text.RegularExpressions;
class bulb
{
public static void Main()
{
string str;
str= Console.ReadLine();
Regex reg= new Regex(" |, ");
StringBuilder sb= new StringBuilder();
int count=1;
foreach(string sub in reg.Split(str))
{
sb.AppendFormat("{0}:{1}n",count++,sub);
}
Console.WriteLine(sb);
}
}
Dr. Neeraj Kumar
Pandey

More Related Content

What's hot (20)

Java Collections
Java  Collections Java  Collections
Java Collections
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Inheritance C#
Inheritance C#Inheritance C#
Inheritance C#
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Lecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptxLecture_7-Encapsulation in Java.pptx
Lecture_7-Encapsulation in Java.pptx
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners Object Oriented Programming Concepts for beginners
Object Oriented Programming Concepts for beginners
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Java package
Java packageJava package
Java package
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Generics in java
Generics in javaGenerics in java
Generics in java
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 

Similar to Strings in c#

13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text ProcessingIntro C# Book
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processingIntro C# Book
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdfAnanthi68
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processingmaznabili
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotesSowri Rajan
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxShowribabuKanta
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfMegMeg17
 
Dotnet programming concepts difference faqs- 3
Dotnet programming concepts difference faqs- 3Dotnet programming concepts difference faqs- 3
Dotnet programming concepts difference faqs- 3Umar Ali
 
Java Foundations: Strings and Text Processing
Java Foundations: Strings and Text ProcessingJava Foundations: Strings and Text Processing
Java Foundations: Strings and Text ProcessingSvetlin Nakov
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating stringsJancypriya M
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptxDilanAlmsa
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures topu93
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesPrabu U
 

Similar to Strings in c# (20)

13 Strings and Text Processing
13 Strings and Text Processing13 Strings and Text Processing
13 Strings and Text Processing
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Java String
Java String Java String
Java String
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdf
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
Unitii classnotes
Unitii classnotesUnitii classnotes
Unitii classnotes
 
manipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptxmanipulation of Strings+PPT.pptx
manipulation of Strings+PPT.pptx
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Dotnet programming concepts difference faqs- 3
Dotnet programming concepts difference faqs- 3Dotnet programming concepts difference faqs- 3
Dotnet programming concepts difference faqs- 3
 
Java Foundations: Strings and Text Processing
Java Foundations: Strings and Text ProcessingJava Foundations: Strings and Text Processing
Java Foundations: Strings and Text Processing
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 
lecture-5 string.pptx
lecture-5 string.pptxlecture-5 string.pptx
lecture-5 string.pptx
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
 

More from Dr.Neeraj Kumar Pandey

Business cases for the need of cloud computing
Business cases for the need of cloud computingBusiness cases for the need of cloud computing
Business cases for the need of cloud computingDr.Neeraj Kumar Pandey
 
cloud computing:Types of virtualization
cloud computing:Types of virtualizationcloud computing:Types of virtualization
cloud computing:Types of virtualizationDr.Neeraj Kumar Pandey
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#Dr.Neeraj Kumar Pandey
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkDr.Neeraj Kumar Pandey
 

More from Dr.Neeraj Kumar Pandey (19)

Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
Structure in c#
Structure in c#Structure in c#
Structure in c#
 
Program control statements in c#
Program control statements in c#Program control statements in c#
Program control statements in c#
 
Operators and expression in c#
Operators and expression in c#Operators and expression in c#
Operators and expression in c#
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
 
Dot net assembly
Dot net assemblyDot net assembly
Dot net assembly
 
Cloud introduction
Cloud introductionCloud introduction
Cloud introduction
 
Role of cloud computing in scm
Role of cloud computing in scmRole of cloud computing in scm
Role of cloud computing in scm
 
Public cloud
Public cloudPublic cloud
Public cloud
 
cloud computing Multi cloud
cloud computing Multi cloudcloud computing Multi cloud
cloud computing Multi cloud
 
Ibm bluemix case study
Ibm bluemix case studyIbm bluemix case study
Ibm bluemix case study
 
Business cases for the need of cloud computing
Business cases for the need of cloud computingBusiness cases for the need of cloud computing
Business cases for the need of cloud computing
 
cloud computing:Types of virtualization
cloud computing:Types of virtualizationcloud computing:Types of virtualization
cloud computing:Types of virtualization
 
cloud computing: Vm migration
cloud computing: Vm migrationcloud computing: Vm migration
cloud computing: Vm migration
 
Cloud Computing: Virtualization
Cloud Computing: VirtualizationCloud Computing: Virtualization
Cloud Computing: Virtualization
 
Dot net introduction
Dot net introductionDot net introduction
Dot net introduction
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
C# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net FrameworkC# lecture 1: Introduction to Dot Net Framework
C# lecture 1: Introduction to Dot Net Framework
 

Recently uploaded

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Strings in c#

  • 1. Strings in C# Dr. Neeraj Kumar Pandey
  • 2. Strings in C#  In C# System.String class is used to manipulate strings.  System.String is a very powerful and versatile class, but it is not by any means the only string-related class in the .NET armory.  System.Text and System.Text.RegularExpression namespaces are also used in Building Strings,Formatting Expressions and Regular Expression Dr. Neeraj Kumar Pandey
  • 3. Immutable Strings  In this type of strings, we cannot modify the characters of a string. Dr. Neeraj Kumar Pandey
  • 5. Comparing Strings Compare() Method int n=string.Compare(s1,s2);  Zero interger, if s1 is equal to s2  A positive Integer (1) , if s1 is greater than s2  A negative integer(-1), if s1 is less than s2 Equals() Method There are two versions of Equals method. They are implemented as follows:- bool b1= s2.Equals(s1); bool b2= string.Equals(s2,s1); These methods returns a Boolean value true if s1 and s2 are equal, otherwise false. The == Operator bool b3= (s1==s2); //b3 is true if they are equal We very often use such statements in decision statements, like:- if(s1==s2) Dr. Neeraj Kumar Pandey
  • 6. Mutable Strings  This type of strings are modifiable using the StringBuilder class. StringBuilder str1=new StringBuilder(“hello”); StringBuilder str2=new StringBuilder();  They can grow dynamically as more characters are added to them.  They can grow either unbounded or up to a configurable maximum.  Mutable Strings are also known as dynamic strings. Dr. Neeraj Kumar Pandey
  • 7. Mutable Strings(Contd..)  The System.Text namespace contains the class StringBuilder, therefore we must include the using System.Text directive for creating and manipulating mutable strings. Dr. Neeraj Kumar Pandey
  • 8. Mutable String Program using System; using System.Text; class strbuild { public static void Main() { string str1,str2; Console.WriteLine("Enter first string"); str1=Console.ReadLine(); Console.WriteLine("Enter Second string"); str2=Console.ReadLine(); StringBuilder s1 = new StringBuilder(str1); StringBuilder s2 = new StringBuilder(str2); //1.Appending a String s1.Append("Smile"); // Console.WriteLine("String After Append :" +s1); //2.Append Format s2.AppendFormat("1)s2 after Append Format {0}",s2); s1.AppendFormat("2)s1 after Append Format {0}",s1); //3.Ensure Capacity int x=s1.EnsureCapacity(30); //4.Inserting a String s2.Insert(3,"Life"); //5.Remove s1.Remove(5,3); //6.Replace s2.Replace('A', '*'); //7.Capacity int y= s1.Capacity; Console.WriteLine("Capacity is"+y); s1.Capacity=100; y=s1.Capacity; Console.WriteLine("New Capacity is"+y); //8.Length int z = s1.Length; int v = s2.Length; Console.WriteLine(" Length of s1 "+ z); Console.WriteLine("Length of s2"+ v); //9.MaxCapacity int c= s1.MaxCapacity; Console.WriteLine("Max Capacity"+s1); //10.setting a character int n=s2.Length; s2[n-1]='@'; } } Dr. Neeraj Kumar Pandey
  • 9. Regular Expression  A regular expression may be applied to a text to accomplish tasks such as :-  To locate substring and return them  To modify one or more substrings and return them  To identify substrings that begins with or end with a pattern of characters.  To find all the words that begin with a group of characters and end with some other characters  To find all the occurrences of a substring pattern.  System.Text.RegualrExpressions supports a number of classes that can be used for searching, matching and modifying a text document.The important classes are:-  Regex, MathCollection, Match. Dr. Neeraj Kumar Pandey
  • 10. Regular Expression Program using System; using System.Text; using System.Text.RegularExpressions; class bulb { public static void Main() { string str; str= Console.ReadLine(); Regex reg= new Regex(" |, "); StringBuilder sb= new StringBuilder(); int count=1; foreach(string sub in reg.Split(str)) { sb.AppendFormat("{0}:{1}n",count++,sub); } Console.WriteLine(sb); } } Dr. Neeraj Kumar Pandey