StringFunctions.

Substring(string, int, int) Method

Summary

Returns a substring of the specified string.
Assembly
NAnt.Core.dll
Namespace
NAnt.Core.Functions
Containing Type
StringFunctions

Syntax

[Function("substring")]
public static string Substring(string str, int startIndex, int length)

Examples

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

Attributes

Type Description
FunctionAttribute Indicates that the method should be exposed as a function in NAnt build files.

Parameters

Name Type Description
str string input string
startIndex int position of the start of the substring
length int the length of the substring

Return Value

Type Description
string

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.