Instant methods: middle()

The instant method middle() returns the middle part from a string operand.

Declaration

string string.middle( int32 aIndex, int32 aCount )

Parameters

aIndex

The character position within the original string indicating the first character to copy. The characters are numbered starting with index 0.

aCount

Maximal number of consecutive characters to copy.

Discussion

The middle() method copies up to aCount characters from the string, in context of which it has been called. The characters are copied starting with the character at position specified in the parameter aIndex. The method returns the copied characters in a new string without modifying the original string operand. If aCount <= 0 the method returns always an empty string "". For example:

var string s1 = "green blue red"; var string result = s1.middle( 0, 5 ); // result = "green" var string result = s1.middle( 6, 4 ); // result = "blue" var string result = s1.middle( 11, 3 ); // result = "red" var string result = s1.middle( -2, 7 ); // result = "green" var string result = s1.middle( 11, 10 ); // result = "red" var string result = s1.middle( 0, -10 ); // result = ""