Summary

Section 16.2 Fundamentals of Characters and Strings

  • Characters are the fundamental building blocks of C# program code. Every program is composed of a sequence of characters that’s interpreted by the compiler as a series of instructions used to accomplish a task.

  • A string is a series of characters treated as a single unit. A string may include letters, digits and the various special characters: +, -, *, /, $ and others.

Section 16.3 string Constructors

  • All strings are immutable—their character contents cannot be changed after they’re created.

Section 16.4 string Indexer, Length Property and CopyTo Method

  • P roperty Length determines the number of characters in a string.

  • The string indexer receives an integer argument as the position number and returns the character at that position. The first element of a string is considered to be at position 0.

  • Attempting to access a character that’s outside a string’s bounds results in an IndexOutOfRange-Exception.

  • Method CopyTo copies a specified number of characters from a string into a char array.

Section 16.5 Comparing strings

  • Some string-comparison capabilities use word sorting rules that depend on the computer’s currently selected culture.

  • Method Equals and the overloaded equality operator (==) can each be used to compare the contents of two strings for equality.

  • Method CompareTo returns 0 if the strings are equal, a negative number if the string that invokes CompareTo is less than the string passed as an argument and a positive number if the string that invokes CompareTo is greater than the string passed as an argument.

  • string methods StartsWith and EndsWith determine whether a string starts or ends with the characters specified as an argument, respectively.

Section 16.6 Locating Characters and Substrings in strings

  • string method IndexOf locates the first occurrence of a character or a substring in a string. Method LastIndexOf locates the last occurrence of a character or a substring in a string.

Section 16.7 Extracting Substrings from strings

  • Class string provides two Substring methods to enable a new string to be created by copying part of an existing string.

Section 16.8 Concatenating strings

  • The static method Concat of class string concatenates two strings and returns a new string containing the characters from both original strings.

Section 16.10 Class StringBuilder

  • Once a string is created, its contents can never change. Class StringBuilder (namespace System.Text) is available for creating and manipulating strings that can change.

Section 16.11 Length and Capacity Properties, EnsureCapacity Method and Indexer of Class StringBuilder

  • Class StringBuilder provides Length and Capacity properties to return, respectively, the number of characters currently in a StringBuilder and the number of characters that can be stored in a StringBuilder without allocating more memory. These properties also can be used to increase or decrease the StringBuilder’s length or the capacity.

  • Method EnsureCapacity allows you to guarantee that a StringBuilder has a minimum capacity.

Section 16.12 Append and AppendFormat Methods of Class StringBuilder

  • Class StringBuilder provides Append and AppendFormat methods to allow various types of values to be added to the end of a StringBuilder.

Section 16.13 Insert, Remove and Replace Methods of Class StringBuilder

  • Class StringBuilder provides many overloaded Insert methods to allow various types of values to be inserted at any position in a StringBuilder. Versions are provided for each simple type and for character arrays, strings and Objects.

  • Class StringBuilder also provides method Remove for deleting any portion of a StringBuilder.

  • StringBuilder method Replace searches for a specified string or character and substitutes another in its place.

Section 16.14 Char Methods

  • The simple types are actually aliases for struct types.

  • All struct types derive from class ValueType, which in turn derives from object.

  • All struct types are implicitly sealed.

  • Char is a struct that represents characters.

  • Method Char.IsDigit determines whether a character is a defined Unicode digit.

  • Method Char.IsLetter determines whether a character is a letter.

  • Method Char.IsLetterOrDigit determines whether a character is a letter or a digit.

  • Method Char.IsLower determines whether a character is a lowercase letter.

  • Method Char.IsUpper determines whether a character is an uppercase letter.

  • Method Char.ToUpper converts a lowercase character to its uppercase equivalent.

  • Method Char.ToLower converts an uppercase character to its lowercase equivalent.

  • Method Char.IsPunctuation determines whether a character is a punctuation mark.

  • Method Char.IsSymbol determines whether a character is a symbol.

  • Method Char.IsWhiteSpace determines whether a character is a whitespace character.

  • Method Char.CompareTo compares two character values.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset