Section 15.5. Summary


15.5. 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.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net