SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
Chapter 10
Immutable Strings
string objects are immutable, i.e. we cannot modify the characters contained in them. The string is an
alias for the predefined System.String class in the Common Language Runtime (CLR). The build-in
operations produce a modified version of the string rather than modifying the string on which the
method is called.
Compare() – Compares the strings CompareTo() – Compares the current instance
with another instance
ConCat() – Concatenates two or more strings Copy() – Creates a new string by copying another
CopyTo() – Copies a specified number of chars to
an array of Unicode chars
Equals() – Determines if two strings are equal
Join() – Joins an array of strings together PadLeft() – Left-aligns the strings in a field
PadRight() – Right-aligns the strings in a field Remove () – Deletes characters from the string
Substring() – Extracts a suvbstring ToLower() – Returns a lower-case version of
string
ToUpper() - Returns a upper-case version of string Trim() – Removes white space from the string
TrimEnd() – Removes a string of characters from
the end of the string
TrimStart() – Removes a string of characters from
beginning of the string
Mutable Strings
Mutalbe strings that are modifiable can be created using StringBuilder class
Eg. StringBuilder str1 = new StringBuilder(“abc”);
They grow dynamically as more characters are added to them. Mutable strings are also known as
dynamic strings.
StringBuilder Methods are :
- Append() – Appends a string,
AppendFormat() – Appends strings using a specific format
EnsureCapacity()
– Ensures sufficient size,
Insert() – Inserts a string at a specified position,
Remove() Removes the specified characters
Replace () – Replaces all instances of a character with the specified one
StringBuilder Properties :- Capacity – To retrieve or set the number of characters the object can hold,
Length – To retrieve or set the length
MaxCapacity – To retrieve the maximum capacity of the object,
[ ] – To get or set a character at a specified position
Regular Expressions
- Regular expressions provide a powerful tool for searching and manipulating a large text.
- A regular expression may be applied to a text to accomplish tasks such as
a) to locate the substrings and locate them
b) to modify one or more substrings and return
c) to identify substrings that begin with or end with a pattern of characters
d) to find all words that begin with a group of characters and end with some other characters.
e) To find all the occurrences of a substring patterns
- A regular expression also known as a pattern string is a string containing two types of characters
Literals, Metacharacters, Literals are characters that search and match in the text. Metacharacters are
special characters that give commands to the regular expression parser.
Eg of regular Expressions are “bm” – Any word beginning with m, “erb” – Any word ending
with er “BxB” – Any x in middle of word.
“bms*erb” – Any word beginning with m and ending with er “|,” – Any word separated by a
space or comma
Here, b, B, s* are metacharacters and m, er, x, comma are literals.
The namespace System.Text.RegularExpressions support a number of classes that can be used for
searching, matching and modifying a text document. The important classes are Regex, MatchCollection,
Match
Distinguish between String and StringBuilder class
String Class – The string class lies in the
namespace System
StringBuilder Class – the StringBuilder class lies in
the namespace System.Text
Immutable strings i.e. a string whose character
cannot be modified can be created using the
string class
Mutable strings can be created using the StringBuilder
class.
All operations produce a modified version of
string rather than modifying the string on
which the method is called.
All operation modify the original string on which the
method is called. Hence these type of strings are also
known as dynamic strings.

Más contenido relacionado

La actualidad más candente

Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
 Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings  Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings ijistjournal
 
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS SubstringsSpace Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS Substringsijistjournal
 
Comparative Adjetive
Comparative AdjetiveComparative Adjetive
Comparative AdjetiveSaraMK10
 
Formal language
Formal languageFormal language
Formal languageRajendran
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9Vince Vo
 

La actualidad más candente (8)

Regular languag regular set
Regular languag regular setRegular languag regular set
Regular languag regular set
 
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
 Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings  Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
 
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS SubstringsSpace Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
 
Language
LanguageLanguage
Language
 
Comparative Adjetive
Comparative AdjetiveComparative Adjetive
Comparative Adjetive
 
Huffman
HuffmanHuffman
Huffman
 
Formal language
Formal languageFormal language
Formal language
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 

Destacado (10)

การโปรแกรมภาษาซีชาร์ป
การโปรแกรมภาษาซีชาร์ปการโปรแกรมภาษาซีชาร์ป
การโปรแกรมภาษาซีชาร์ป
 
C# chap 1
C# chap 1C# chap 1
C# chap 1
 
C# programs
C# programsC# programs
C# programs
 
12 exception handling
12 exception handling12 exception handling
12 exception handling
 
Tech talk webtech
Tech talk webtechTech talk webtech
Tech talk webtech
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Programming in c#
Programming in c#Programming in c#
Programming in c#
 
C# Tutorial
C# Tutorial C# Tutorial
C# Tutorial
 
C# basics
 C# basics C# basics
C# basics
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 

Similar a C# chap 10

Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfMegMeg17
 
13string in c#
13string in c#13string in c#
13string in c#Sireesh K
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle databaseAmrit Kaur
 
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips  Some hints for approa.docxCSE 220 Assignment 3 Hints and Tips  Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docxfaithxdunce63732
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arraysphanleson
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular ExpressionsMukesh Tekwani
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...jaychoudhary37
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesPrabu U
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and StringsEduardo Bergavera
 
Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov, Introduction to Python, Lecture3Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov, Introduction to Python, Lecture3Anton Kasyanov
 

Similar a C# chap 10 (20)

C# String
C# StringC# String
C# String
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
 
Andrei's Regex Clinic
Andrei's Regex ClinicAndrei's Regex Clinic
Andrei's Regex Clinic
 
13string in c#
13string in c#13string in c#
13string in c#
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
 
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips  Some hints for approa.docxCSE 220 Assignment 3 Hints and Tips  Some hints for approa.docx
CSE 220 Assignment 3 Hints and Tips Some hints for approa.docx
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
Python - Regular Expressions
Python - Regular ExpressionsPython - Regular Expressions
Python - Regular Expressions
 
Python strings
Python stringsPython strings
Python strings
 
What-is-String-in-Java.pptx
What-is-String-in-Java.pptxWhat-is-String-in-Java.pptx
What-is-String-in-Java.pptx
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_06-Dec...
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
M C6java7
M C6java7M C6java7
M C6java7
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov, Introduction to Python, Lecture3Anton Kasyanov, Introduction to Python, Lecture3
Anton Kasyanov, Introduction to Python, Lecture3
 
Regex lecture
Regex lectureRegex lecture
Regex lecture
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 

Más de Shehrevar Davierwala

Más de Shehrevar Davierwala (20)

Introduction_Swift
Introduction_SwiftIntroduction_Swift
Introduction_Swift
 
PsudoCode.pptx
PsudoCode.pptxPsudoCode.pptx
PsudoCode.pptx
 
Number System.pptx
Number System.pptxNumber System.pptx
Number System.pptx
 
Java Script (Module 1).pptx
Java Script (Module 1).pptxJava Script (Module 1).pptx
Java Script (Module 1).pptx
 
Website in Clicks Day 2
Website in Clicks Day 2Website in Clicks Day 2
Website in Clicks Day 2
 
Develop Website in Clicks
Develop Website in ClicksDevelop Website in Clicks
Develop Website in Clicks
 
Build Virtual Assistant Using AI
Build Virtual Assistant Using AI Build Virtual Assistant Using AI
Build Virtual Assistant Using AI
 
Build brand reputation using facebook
Build brand reputation using facebookBuild brand reputation using facebook
Build brand reputation using facebook
 
Digital Marketing Session 2
Digital Marketing Session 2Digital Marketing Session 2
Digital Marketing Session 2
 
Learn Digital Marketing : 0 to Hero Day 1
Learn Digital Marketing :  0 to Hero Day 1 Learn Digital Marketing :  0 to Hero Day 1
Learn Digital Marketing : 0 to Hero Day 1
 
Standard template
Standard templateStandard template
Standard template
 
Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective  Digital Marketing for Sustainable Business - Afghan Perspective
Digital Marketing for Sustainable Business - Afghan Perspective
 
Developing stunning website in clicks - 2
Developing stunning website in clicks - 2Developing stunning website in clicks - 2
Developing stunning website in clicks - 2
 
Developing stunning website in clicks
Developing stunning website in clicksDeveloping stunning website in clicks
Developing stunning website in clicks
 
Google forms for data analysis
Google forms for data analysisGoogle forms for data analysis
Google forms for data analysis
 
Webdesign session1
Webdesign session1Webdesign session1
Webdesign session1
 
Tech talk php_cms
Tech talk php_cmsTech talk php_cms
Tech talk php_cms
 
Ph pbasics
Ph pbasicsPh pbasics
Ph pbasics
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Java operators
Java operatorsJava operators
Java operators
 

Último

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Último (20)

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

C# chap 10

  • 1. Chapter 10 Immutable Strings string objects are immutable, i.e. we cannot modify the characters contained in them. The string is an alias for the predefined System.String class in the Common Language Runtime (CLR). The build-in operations produce a modified version of the string rather than modifying the string on which the method is called. Compare() – Compares the strings CompareTo() – Compares the current instance with another instance ConCat() – Concatenates two or more strings Copy() – Creates a new string by copying another CopyTo() – Copies a specified number of chars to an array of Unicode chars Equals() – Determines if two strings are equal Join() – Joins an array of strings together PadLeft() – Left-aligns the strings in a field PadRight() – Right-aligns the strings in a field Remove () – Deletes characters from the string Substring() – Extracts a suvbstring ToLower() – Returns a lower-case version of string ToUpper() - Returns a upper-case version of string Trim() – Removes white space from the string TrimEnd() – Removes a string of characters from the end of the string TrimStart() – Removes a string of characters from beginning of the string Mutable Strings Mutalbe strings that are modifiable can be created using StringBuilder class Eg. StringBuilder str1 = new StringBuilder(“abc”); They grow dynamically as more characters are added to them. Mutable strings are also known as dynamic strings. StringBuilder Methods are : - Append() – Appends a string, AppendFormat() – Appends strings using a specific format EnsureCapacity() – Ensures sufficient size, Insert() – Inserts a string at a specified position, Remove() Removes the specified characters Replace () – Replaces all instances of a character with the specified one
  • 2. StringBuilder Properties :- Capacity – To retrieve or set the number of characters the object can hold, Length – To retrieve or set the length MaxCapacity – To retrieve the maximum capacity of the object, [ ] – To get or set a character at a specified position Regular Expressions - Regular expressions provide a powerful tool for searching and manipulating a large text. - A regular expression may be applied to a text to accomplish tasks such as a) to locate the substrings and locate them b) to modify one or more substrings and return c) to identify substrings that begin with or end with a pattern of characters d) to find all words that begin with a group of characters and end with some other characters. e) To find all the occurrences of a substring patterns - A regular expression also known as a pattern string is a string containing two types of characters Literals, Metacharacters, Literals are characters that search and match in the text. Metacharacters are special characters that give commands to the regular expression parser. Eg of regular Expressions are “bm” – Any word beginning with m, “erb” – Any word ending with er “BxB” – Any x in middle of word. “bms*erb” – Any word beginning with m and ending with er “|,” – Any word separated by a space or comma Here, b, B, s* are metacharacters and m, er, x, comma are literals. The namespace System.Text.RegularExpressions support a number of classes that can be used for searching, matching and modifying a text document. The important classes are Regex, MatchCollection, Match Distinguish between String and StringBuilder class String Class – The string class lies in the namespace System StringBuilder Class – the StringBuilder class lies in the namespace System.Text Immutable strings i.e. a string whose character cannot be modified can be created using the string class Mutable strings can be created using the StringBuilder class. All operations produce a modified version of string rather than modifying the string on which the method is called. All operation modify the original string on which the method is called. Hence these type of strings are also known as dynamic strings.