6. C# Strings
6. C# Strings
Example:
Console.WriteLine(name);
C# String Interpolation
Another option of string concatenation, is string interpolation, which
substitutes values of variables into placeholders in a string.
string firstName = "John";
string lastName = "Doe";
Console.WriteLine(myString[2]);
Another useful method is Substring(), which extracts the characters from a
string, starting from the specified character position/index, and returns a new
string.
This method is often used together with IndexOf() to get the specific character
position.
string name = "John Doe";
int charPos = name.IndexOf("D");//5
int substring_length=2;
string lastName = name.Substring(charPos,substring_length); //Do
Console.WriteLine(lastName); //Do
Strings - Special Characters
string txt = "We are \"Batch 60B\" of UU.";
The solution to avoid this problem, is to use the backslash escape character.
The backslash (\) escape character turns special characters into string characters