Professional Documents
Culture Documents
Strings are used for storing text. A string variable contains a collection of
characters surrounded by double quotes:
string s = “Hello” ;
In C# programming, string is another kind of data type that represents Unicode
Characters. It is the alias of System.String, however, you can also write
System.String instead of a string. It is the sequence of character in which each
character is a Unicode character.
C# string function
A string in C# is actually an object, which contain properties and methods that
can perform certain operations on strings.
1- String Length
Example
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Console.WriteLine("The length of the txt string is: " + txt.Length);
Output
Example
1
3- String Concatenation
Example
Note: You can also use the string.Concat() method to concatenate two strings:
Example
4- Access Strings
You can access the characters in a string by referring to its index number inside
square brackets [].
Example
Note: String indexes start with 0: [0] is the first character. [1] is the second
character, etc.
2
5- Indexing of a specific character
You can also find the index position of a specific character in a string, by using
the IndexOf() method:
Example
Example
// Full string
7- Insert( )
The responsible of this method is Insert the string or character in the specific
index.
Example
// Full string
3
8- Remove( )
This method deletes all the characters from the specific index to the end, or from
specific index to specified index position.
Example
// Full string
9- Replace( )
This method replaces the character with character, or replace sentence with
sentence
Example
// Full string
10- EndsWith( )
This EndsWith Method checks whether specified character is the last character
of string or not.
Example
// Full string
4
11- StartsWith( )
It checks whether the first character of string is same as specified character.
Example
// Full string