Strings






Summary

  • C# strings can be sorted, searched, and otherwise manipulated.

  • The String class is sealed, meaning it cannot be derived from. It implements the IComparable, IClonable, IConvertible, and IEnumerable interfaces, 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 a foreach statement, 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 would otherwise not be valid within a string.

  • 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 String class also includes methods for finding and extracting substrings, such as IndexOf( ), LastIndexOf( ), and Substring( ).

  • 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 class allows you to assemble the contents of a string with greater efficiency and then to call its ToString( ) method to generate the string you need once it is fully assembled.

  • Regular expressions provide pattern-matching abilities that enable you to search and manipulate text.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows