C Strings

Member Example

// Using property of System.String
string lengthOfString = "How long?";
lengthOfString.Length           // => 9
// Using methods of System.String
lengthOfString.Contains("How"); // => true

Verbatim strings

string longString = @"I can type any characters in here !#@$%^&\*()\_\_+ '' \n \t except double quotes and I will be taken literally. I even work with multiple lines.";

String Members

Member Description
Length A property that returns the length of the string.
Compare() A static method that compares two strings.
Contains() Determines if the string contains a specific substring.
Equals() Determines if the two strings have the same character data.
Format() Formats a string via the {0} notation and by using other primitives.
Trim() Removes all instances of specific characters from trailing and leading characters. Defaults to removing leading and trailing spaces.
Split() Removes the provided character and creates an array out of the remaining characters on either side.

String interpolation

string first = "John";
string last = "Doe";
string name = $"{first} {last}";
Console.WriteLine(name); // => John Doe

String concatenation

string first = "John";
string last = "Doe";
string name = first + " " + last;
Console.WriteLine(name); // => John Doe
Comments