Converts a substring of this string to an array of characters, beginning at a specified point in this string.
[Visual Basic] Overloads Public Function Substring( _ ByVal startIndex As Integer, _ ByVal length As Integer _ ) As String [C#] public string Substring( int startIndex, int length ); [C++] public: String* Substring( int startIndex, int length ); [JScript] public function Substring( startIndex : int, length : int ) : String;
Returns the substring of characters at beginning position of the index (startIndex) through the ending position (startIndex + length- 1).
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | If the substring is greater than the length of this string. |
ArgumentOutOfRangeException | If starting index less than zero. |
ArgumentOutOfRangeException | If number of characters is less than zero. |
String indices are 0-based.
If startIndex is equal to the length of this string and length is 0, then the empty string is returned. The value of this parameter must be greater than or equal to zero and less than or equal to the length of this string.
The length parameter is can be 0, in which case the substring is the empty string. A length of-1 indicates the length of this string.
Managed C++:
String *myString = L"abc"; String::Compare(myString->Substring(2,1), L"c") == 0; // THIS IS TRUE myString->Substring(3,1); // THROWS AN ArgumentOutOfRangeException String::Compare(myString->Substring(3,0), String::Empty) == 0; // THIS IS TRUE
String Class | String Members | System Namespace | String.Substring Overload List | Int32