NAnt SDK Documentation - v0.92 |

# StringFunctions.Substring Method

Returns a substring of the specified string.

[Visual Basic]
<Function(Name:="substring")>
Public Shared Function Substring( _
ByVal str As String, _
ByVal startIndex As Integer, _
ByVal length As Integer _
) As String
[C#]
[Function(Name="substring")]
public static string Substring(
string str,
int startIndex,
int length
);

#### Parameters

str
  input string
startIndex
  position of the start of the substring
length
  the length of the substring

#### Return Value

If the length is greater than zero, the function returns a substring starting at character position startIndex with a length of length characters.

If the length is equal to zero, the function returns an empty string.

#### Exceptions

Exception Type | Condition
--- | ---
ArgumentOutOfRangeException | startIndex or length is less than zero.
ArgumentOutOfRangeException | startIndex is greater than the length of str.
ArgumentOutOfRangeException | startIndex plus length indicates a position not within str.

#### Example

    string::substring('testing string', 0, 4) ==> 'test'

    string::substring('testing string', 8, 3) ==> 'str'

    string::substring('testing string', 8, 0) ==> ''

    string::substring('testing string', -1, 5) ==> ERROR

    string::substring('testing string', 8, -1) ==> ERROR

    string::substring('testing string', 5, 17) ==> ERROR

#### See Also

StringFunctions Class | NAnt.Core.Functions Namespace