06-06-2013, 04:01 PM
Manipulating String
Manipulating String.pptx (Size: 67.78 KB / Downloads: 22)
Introduction
String represent sequence of characters
C# supports two types of strings
Immutable
Mutable
It also supports regular expressions , that can be use for complex string manipulation and pattern matching
Creating String
We can create immutable string by using string object in a number of ways
Assigning string literals
Copying from one object to another
Concatenating two objects
Reading from the keyboard
Using ToString() method
Reading from the keyboard
It is possible to read the string value from keyboard and assign it to string object
Example:
string s1=Console.ReadLine();
On reaching this statement, the computer will wait for a string characters to be entered from keyboard
When return key is pressed, the string will be read and assigned to s1
Verbatim Strings
String can also be created using verbatim
Verbatim string are those which starts with @ symbol
This symbol tells the compiler that string should be used verbatim even if it include escape characters
string s1 = @ “D:\subject\APL”;
In order to obtain the same output without using @ , the input string would be return as follows:
string s1 = “D:\subject\APL”;
\n, \t would be treated as text instead of newline or tab when it precede by @