rsubstring (x, s, n)

The rsubstring(x, s, n) function returns a substring from the parameter x. The substring includes the s character of x and all but the last n characters of x.

The behavior of rsubstring can be expressed in the following way.

rsubstring(x, s, n) = substring(x, s,((length (x) - s) - n))

If s is negative, the substring is started at the s character from the end of the string and counts towards the end.

If n is negative, the substring contains all characters from the s character up to the end of the string.

This function returns a value of type Text.

Common use

 remainder = rsubstring(x, s, 0)

This returns the remainder of a string starting at position s in the string. The third parameter 0 indicates that no characters from the end of the string are omitted.

 remainder = rsubstring(x, 0, 4)

This returns the input string without the last 4 characters.

Examples

 rsubstring ("This is a counting test", 0, 3)
	 

Result: "This is a counting t". 0 sets the start position at the beginning of the input string and 3 indicates that the last three characters from the end of the input string must be left out.

 rsubstring ("This is a counting test", 4, 0)

Result: "s is a counting test". 4 sets the start position in the input string and 0 indicates that no characters must be left out.

rsubstring ("This is a counting test", -8, 3)

Result: "ing t". -8 selects the last 8 characters from the end of the string ( "ing test") and 3 indicates that all but the last 3 characters of that substring are returned.

rsubstring ("This is a counting test", 3, 25)
	 

Result: "", an empty string. The third parameter indicates that 25 characters from the end of the input string must be left out. As there are less than 25 characters in the input string from the start position (parameter two: 3) in the input string, the result is an empty string.