On 18/12/2007, DNNX <6aLLIaPuMoB / gmail.com> wrote: > On 18 дек, 17:54, Robert Klemme <shortcut... / googlemail.com> wrote: > > On one hand you are right. On the other hand, begin and end indexes > > are asymmetric anyway: you know that the starting index is always 0 > > but the ending index can have arbitrary values. ... > > Hm... On the other hand, end and begin indexes are asymmetric anyway: > you know that the ending index is always -1 but the starting index can > have arbitrary values. > > Isn't this a symmetry? > The asymmetry is in that you can chop off "at most 10 characters from the start" with 0...10 but not "at most 10 characters from the end" with -10..-1 because the start that has to be inside the string is the one of which you cannot be sure. You cannot swap the bounds because you get an empty string then. So the symmetric rule for range indexing would be something like this: a) both ends of the range have same sign -> the one with lower absolute value must be inside the string. In other words, the range must intersect with 0...string.length. This is the only option that can create a valid range completely outside of the string (when the condition is not met). b) they have different sign, start is non-negative -> simple. Either they give a range inside the string or a range where the start is higher than end (a..-b => a..length-b), and can always return string, sometimes empty. c) the start is negative, end is positive -> ideally you get something inside the string but you can get range that has both start and end outside of the string - each on different side. Either way it makes sense. It contains part of the string or start is higher than end after evaluating (-a..b => length-a..b) Thanks Michal