String

String CF 1.0, ECMA 1.0, serializable

System (mscorlib.dll) sealed class

This class consists of an immutable array of Char characters and built-in helper functions. Methods that appear to modify a string, such as Concat( ) , actually create and return a new String object. To modify a string directly, use the System.Text.StringBuilder class. This can enhance performance in some routines that make intensive use of string-manipulation operations. In C#, String is aliased as string .

A string is slightly unusual because it is a reference type that behaves like a value type for comparison and assignment operations. Two String objects with the same content but different locations in memory return true when tested for equality. Also, assigning one String to another clones the string itself, rather than just duplicating the reference.

On the other hand, a String is a fully featured object with a Length property and a wide variety of methods for the following: padding or trimming specified characters on either side, converting case, performing inline substitutions (with Replace( ) ), and dividing a string into an array of strings (with Split( ) ). There's also a default indexer that lets you retrieve a single character. Note that strings are zero-based , and the first character is string[0] .

You can create a string made up of a single repeated character by using an alternate constructor and supplying a char and the number of repetitions.

 public sealed class  String  : IComparable, ICloneable, IConvertible, IEnumerable {  // Public Constructors  public  String  (char   *value   );    public  String  (char   *value   , int   startIndex   , int   length   );    public  String  (char[ ]   value   );    public  String  (char[ ]   value   , int   startIndex   , int   length   );    public  String  (char   c   , int   count   );    public  String  (sbyte   *value   );    public  String  (sbyte   *value   , int   startIndex   , int   length   );    public  String  (sbyte   *value   , int   startIndex   , int   length   , System.Text.Encoding   enc   );  // Public Static Fields  public static readonly string  Empty  ;  // Public Instance Properties  public int  Length  {get; }    public char  this  [int   index   ]{get; }  // Public Static Methods  public static int  Compare  (string   strA   , int   indexA   , string   strB   , int   indexB   , int   length   );    public static int  Compare  (string   strA   , int   indexA   , string   strB   , int   indexB   , int   length   ,          bool   ignoreCase   );    public static int  Compare  (string   strA   , int   indexA   , string   strB   , int   indexB   , int   length   ,          bool   ignoreCase   , System.Globalization.CultureInfo   culture   );    public static int  Compare  (string   strA   , string   strB   );    public static int  Compare  (string   strA   , string   strB   , bool   ignoreCase   );    public static int  Compare  (string   strA   , string   strB   , bool   ignoreCase   ,          System.Globalization.CultureInfo   culture   );    public static int  CompareOrdinal  (string   strA   , int   indexA   , string   strB   , int   indexB   , int   length   );    public static int  CompareOrdinal  (string   strA   , string   strB   );    public static string  Concat  (object   arg0   );    public static string  Concat  (params object[ ]   args   );    public static string  Concat  (object   arg0   , object   arg1   );    public static string  Concat  (object   arg0   , object   arg1   , object   arg2   );    public static string  Concat  (object   arg0   , object   arg1   , object   arg2   , object   arg3   );    public static string  Concat  (params string[ ]   values   );    public static string  Concat  (string   str0   , string   str1   );    public static string  Concat  (string   str0   , string   str1   , string   str2   );    public static string  Concat  (string   str0   , string   str1   , string   str2   , string   str3   );    public static string  Copy  (string   str   );    public static bool  Equals  (string   a   , string   b   );    public static string  Format  (IFormatProvider   provider   , string   format   , params object[ ]   args   );    public static string  Format  (string   format   , object   arg0   );    public static string  Format  (string   format   , params object[ ]   args   );    public static string  Format  (string   format   , object   arg0   , object   arg1   );    public static string  Format  (string   format   , object   arg0   , object   arg1   , object   arg2   );    public static string  Intern  (string   str   );    public static string  IsInterned  (string   str   );    public static string  Join  (string   separator   , string[ ]   value   );    public static string  Join  (string   separator   , string[ ]   value   ,  int   startIndex   , int   count   );    public static bool operator  !=  (string   a   , string   b   );    public static bool operator  =  =  (string   a   , string   b   );  // Public Instance Methods  public object  Clone  ( );  // implements ICloneable  public int  CompareTo  (object   value   );  // implements IComparable  public int  CompareTo  (string   strB   );    public void  CopyTo  (int   sourceIndex   , char[ ]   destination   , int   destinationIndex   , int   count   );    public bool  EndsWith  (string   value   );    public override bool  Equals  (object   obj   );  // overrides object  public bool  Equals  (string   value   );    public CharEnumerator  GetEnumerator  ( );    public override int  GetHashCode  ( );  // overrides object  public TypeCode  GetTypeCode  ( );  // implements IConvertible  public int  IndexOf  (char   value   );    public int  IndexOf  (char   value   , int   startIndex   );    public int  IndexOf  (char   value   , int   startIndex   , int   count   );    public int  IndexOf  (string   value   );    public int  IndexOf  (string   value   , int   startIndex   );    public int  IndexOf  (string   value   , int   startIndex   , int   count   );    public int  IndexOfAny  (char[ ]   anyOf   );    public int  IndexOfAny  (char[ ]   anyOf   , int   startIndex   );    public int  IndexOfAny  (char[ ]   anyOf   , int   startIndex   , int   count   );    public string  Insert  (int   startIndex   , string   value   );    public int  LastIndexOf  (char   value   );    public int  LastIndexOf  (char   value   , int   startIndex   );    public int  LastIndexOf  (char   value   , int   startIndex   , int   count   );    public int  LastIndexOf  (string   value   );    public int  LastIndexOf  (string   value   , int   startIndex   );    public int  LastIndexOf  (string   value   , int   startIndex   , int   count   );    public int  LastIndexOfAny  (char[ ]   anyOf   );    public int  LastIndexOfAny  (char[ ]   anyOf   , int   startIndex   );    public int  LastIndexOfAny  (char[ ]   anyOf   , int   startIndex   , int   count   );    public string  PadLeft  (int   totalWidth   );    public string  PadLeft  (int   totalWidth   , char   paddingChar   );    public string  PadRight  (int   totalWidth   );    public string  PadRight  (int   totalWidth   , char   paddingChar   );    public string  Remove  (int   startIndex   , int   count   );    public string  Replace  (char   oldChar   , char   newChar   );    public string  Replace  (string   oldValue   , string   newValue   );    public string[ ]  Split  (params char[ ]   separator   );    public string[ ]  Split  (char[ ]   separator   , int   count   );    public bool  StartsWith  (string   value   );    public string  Substring  (int   startIndex   );    public string  Substring  (int   startIndex   , int   length   );    public char[ ]  ToCharArray  ( );    public char[ ]  ToCharArray  (int   startIndex   , int   length   );    public string  ToLower  ( );    public string  ToLower  (System.Globalization.CultureInfo   culture   );    public override string  ToString  ( );  // overrides object  public string  ToString  (IFormatProvider   provider   );  // implements IConvertible  public string  ToUpper  ( );    public string  ToUpper  (System.Globalization.CultureInfo   culture   );    public string  Trim  ( );    public string  Trim  (params char[ ]   trimChars   );    public string  TrimEnd  (params char[ ]   trimChars   );    public string  TrimStart  (params char[ ]   trimChars   ); } 

Returned By

Multiple types

Passed To

Multiple types



C# in a Nutshell
C # in a Nutshell, Second Edition
ISBN: 0596005261
EAN: 2147483647
Year: 2005
Pages: 963

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