C# Strings

 C# Strings

Strings are used to store text, a string variable contains a collection of characters surrounded by Double quotation " ".

Example:

Creating a variable of type string and assigning a value to it


Output: Sudharsan

String Length:

A string in C# is actually an object which used to perform certain operations in strings

For Ex: length  of the string can be found by using the Length property



String Methods which returns string converted values
ToUppercase() and ToLowercase()

Example

String Concatenation:

In the below given example + operator that can be used between strings to combine them is called concatenation

 

we can also use string.Concat() method to combine two strings


Another option of string concatenation is string interpolation, which substitutes a value into the placeholders in a string. 

NOTE: We have to use the dollar($) symbol when using the String interpolation method.


Access Strings

we can access a character in a string by referring to its index number inside a square brackets [].
This example prints the first character in mystring


we can also find a index position of a special character of a string, by using the IndexOf( ) method.



Another useful method is Substring( ), which extracts the character from the string, starting from the specified character/index which returns a string, which is often used with IndexOf( ) method


Note :
C# uses + Operator for both Addtition and Concatenation

Below here, we use + operator for an integer for addition,


Below here, we use + operator for string for concatenation,













Post a Comment

Previous Post Next Post

نموذج الاتصال