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

This forum is for discussing the development of Rel examples and sample applications.
Post Reply
HughDarwen
Posts: 124
Joined: Sat May 24, 2008 4:49 pm

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

Post 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
Dave
Site Admin
Posts: 372
Joined: Sun Nov 27, 2005 7:19 pm

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

Post 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."
Post Reply