Page 1 of 1

Is SUBSTRING(CHAR, INT, INT) correctly defined?

Posted: Fri Dec 02, 2011 10:32 am
by HughDarwen
I refer to the operator provided in OperatorsChar.d.

SUBSTRING('abcde',3,4) returns 'd' when I was expecting 'de'. It seems that the start position is using origin 0 while the end position uses origin 1. Alternatively, the third operand is to be interpreted as "up to but not including"--reminiscent of the mathematical standard of closed-open notation for intervals.

Hugh

Re: Is SUBSTRING(CHAR, INT, INT) correctly defined?

Posted: Sun Dec 11, 2011 4:16 pm
by Dave
SUBSTRING is correct, at least to the extent that it simply exposes the functionality of Java's String.substring(int beginIndex, int endIndex) method. From the Java documentation:

"[Substring] [r]eturns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex."

..and...

"beginIndex - the beginning index, inclusive."
"endIndex - the ending index, exclusive."