Summary
C# strings can be sorted, searched, and otherwise manipulated.
The
Stringclass is sealed, meaning it cannot be derived from. It implements theIComparable, ICloneable, IConvertible, andIEnumerableinterfaces, indicating that you can compare two strings (to sort them), clone a string (to create a duplicate), convert a string to another type (for example, converting the string “15” to the integer 15), and enumerate over a string using aforeachstatement, respectively.A string literal is a quoted string of characters assigned to a variable of type
string. This is the most common use of strings.Escape characters allow you to add special characters to strings that you would otherwise not be able to represent.
A verbatim string literal starts with an
@symbol and indicates that the string should be used exactly as is. Verbatim strings do not require escape characters.You can concatenate strings with the
Concat( )method or the+operator.You can copy strings with the
Copy( )method or the=operator.You can test for equality of two strings with the
Equals( )method or the==operator.The
Stringclass also includes methods for finding and extracting substrings, such asIndexOf( ), LastIndexOf( ), andSubstring( ).You can use the
Split( )method with an array of delimiters to divide a string into substrings.Strings are immutable. Every time you appear to modify a string, a copy is made with the modification and the original string is released to the garbage collector.
The
StringBuilder ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access