NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

String.Substring (Int32, Int32)

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;

Parameters

startIndex
The position of this string at which the substring begins.
length
The number of characters in the substring.

Return Value

Returns the substring of characters at beginning position of the index (startIndex) through the ending position (startIndex + length- 1).

Exceptions

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.

Remarks

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.

Example

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

See Also

String Class | String Members | System Namespace | String.Substring Overload List | Int32