The substring (x, s, n) function returns a substring from the parameter x. The substring starts at and will include the s-th character of x and will contain n characters.
If x does not contain sufficient characters the result will be truncated.
If s is negative, the substring will start at the s-th character from the end of the string and count towards the end.
If n is zero or negative, the substring will return an empty string.
This function returns a value of type Text.
substring ("This is a counting test", 4, 9)
Result: "s is a co"
substring ("This is a counting test", 4,0)
Result: "", an empty string
substring ("This is a counting test", 4, -5)
Result: "", an empty string
substring ("This is a counting test", -4, 9)
Result: "test". The start position is taken from the end of the string because –4 is negative. Of the 9 characters possible only 4 are present and returned as the result.
substring ("This is a test in counting", 4, 25)
Result: "s is a test in counting". Of the asked for 25 characters only 23 are present in the string. These are returned.