4. Lesson Objectives
Apply the different methods in a C# program.
Explain how they are implemented in C# and process text content.
Learn the different methods for manipulating a text.
6. String Defined
• A string is a sequence of characters stored in a certain address in
memory.
• In layman’s term, a string is a sequence of characters enclosed in
double quotation marks.
• The class System.String enables us to handle strings in C#.
• For declaring the strings we will continue using the keyword string,
which is an alias in C# of the System.String class from .NET
Framework.
• The work with string facilitates us in manipulating the text content:
construction of texts, text search and many other operations.
7. Declaring a String Variable
• A string variable is a sequence of characters whose value changes
throughout the program.
• The value of the string depends on the user input.
9. Declaring a String Literal
• A string literal, also called a string constant is a sequence of characters
whose value does not changed.
• The value of the string is fixed throughout the program.
22. IndexOf()
Reports the zero-based index
of the first occurrence of a
specified Unicode character or
string within this instance.
The method returns -1 if the
character or string is not
found in this instance.
23. LastIndexOf()
Reports the zero-based index
position of the last
occurrence of a specified
Unicode character or string
within this instance. The
method returns -1 if the
character or string is not
found in this instance.
24. Replace()
Returns a new string in which
all occurrences of a specified
Unicode character or String in
the current string are
replaced with another
specified Unicode character or
String.
25. Replace()
Returns a new string in which
all occurrences of a specified
Unicode character or String in
the current string are
replaced with another
specified Unicode character or
String.