SlideShare a Scribd company logo
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.

More Related Content

PDF
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
PPTX
Basic regular expression, extended regular expression
PPTX
Spell Checker and string matching Using BK tree
PPTX
Data types
PPTX
Regular expression (compiler)
PPTX
Regular expressions
PPT
Regular Expression in Action
PDF
Flat unit 2
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Basic regular expression, extended regular expression
Spell Checker and string matching Using BK tree
Data types
Regular expression (compiler)
Regular expressions
Regular Expression in Action
Flat unit 2

What's hot (8)

PPTX
Regular languag regular set
PDF
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
PDF
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
PDF
Language
PPTX
Comparative Adjetive
PDF
Huffman
PPTX
Formal language
PPT
Java căn bản - Chapter9
Regular languag regular set
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Space Efficient Suffix Array Construction using Induced Sorting LMS Substrings
Language
Comparative Adjetive
Huffman
Formal language
Java căn bản - Chapter9
Ad

Viewers also liked (10)

PDF
การโปรแกรมภาษาซีชาร์ป
PDF
PDF
PPT
12 exception handling
PPT
Tech talk webtech
PPT
Introduction To C#
PPT
Programming in c#
PPTX
C# Tutorial
PPT
C# basics
PPT
C# Exceptions Handling
การโปรแกรมภาษาซีชาร์ป
12 exception handling
Tech talk webtech
Introduction To C#
Programming in c#
C# Tutorial
C# basics
C# Exceptions Handling
Ad

Similar to C# chap 10 (20)

PPTX
PPTX
Strings in c#
PPT
13 Strings and text processing
PPTX
13 Strings and Text Processing
PDF
Module 6 - String Manipulation.pdf
PPTX
16 strings-and-text-processing-120712074956-phpapp02
PDF
Lecture 10.pdf
PDF
DSA - Lecture 04
PDF
Core c sharp and .net quick reference
PDF
Core csharp and net quick reference
PPTX
String, string builder, string buffer
PPTX
stringstringbuilderstringbuffer-190830060142.pptx
PPTX
13string in c#
PPTX
javastringexample problems using string class
PPTX
Detailed description of Strings in Python
PPTX
Java string handling
PPT
Strings Arrays
PPT
Java Strings methods and operations.ppt
PPTX
In the given example only one object will be created. Firstly JVM will not fi...
PDF
Rc018 corenet online
Strings in c#
13 Strings and text processing
13 Strings and Text Processing
Module 6 - String Manipulation.pdf
16 strings-and-text-processing-120712074956-phpapp02
Lecture 10.pdf
DSA - Lecture 04
Core c sharp and .net quick reference
Core csharp and net quick reference
String, string builder, string buffer
stringstringbuilderstringbuffer-190830060142.pptx
13string in c#
javastringexample problems using string class
Detailed description of Strings in Python
Java string handling
Strings Arrays
Java Strings methods and operations.ppt
In the given example only one object will be created. Firstly JVM will not fi...
Rc018 corenet online

More from Shehrevar Davierwala (20)

PDF
Introduction_Swift
PPTX
PsudoCode.pptx
PPTX
Number System.pptx
PPTX
Java Script (Module 1).pptx
PPTX
Website in Clicks Day 2
PPTX
Develop Website in Clicks
PPTX
Build Virtual Assistant Using AI
PPTX
Build brand reputation using facebook
PPTX
Digital Marketing Session 2
PPTX
Learn Digital Marketing : 0 to Hero Day 1
DOC
Standard template
PPT
Digital Marketing for Sustainable Business - Afghan Perspective
PPT
Developing stunning website in clicks - 2
PPT
Developing stunning website in clicks
PPTX
Google forms for data analysis
PPT
Webdesign session1
PPT
Tech talk php_cms
PPT
PPT
PPT
Java operators
Introduction_Swift
PsudoCode.pptx
Number System.pptx
Java Script (Module 1).pptx
Website in Clicks Day 2
Develop Website in Clicks
Build Virtual Assistant Using AI
Build brand reputation using facebook
Digital Marketing Session 2
Learn Digital Marketing : 0 to Hero Day 1
Standard template
Digital Marketing for Sustainable Business - Afghan Perspective
Developing stunning website in clicks - 2
Developing stunning website in clicks
Google forms for data analysis
Webdesign session1
Tech talk php_cms
Java operators

Recently uploaded (20)

DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PPTX
Cell Types and Its function , kingdom of life
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Classroom Observation Tools for Teachers
PDF
IGGE1 Understanding the Self1234567891011
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Introduction to Building Materials
PPTX
Lesson notes of climatology university.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Cell Types and Its function , kingdom of life
History, Philosophy and sociology of education (1).pptx
Paper A Mock Exam 9_ Attempt review.pdf.
Orientation - ARALprogram of Deped to the Parents.pptx
Classroom Observation Tools for Teachers
IGGE1 Understanding the Self1234567891011
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
RMMM.pdf make it easy to upload and study
A powerpoint presentation on the Revised K-10 Science Shaping Paper
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Introduction to Building Materials
Lesson notes of climatology university.
Chinmaya Tiranga quiz Grand Finale.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3

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.