$piece

From CacheWiki
Jump to: navigation, search

Last piece

$p(x,delimiter,$l(x,delimiter))

Nth through last pieces

$p(x,delimiter,n,$l(x,delimiter))

but this can be ugly and hard to grok especially if the delimiter is a quoted string like this: $p(x,",",n,$l(x,",")). An often seen alternative is $p(x,delimiter,2,999) which is easier on the eye but fails if the source string happened to contain more than 999 occurrences of the delimiter. As longer and longer strings get supported this becomes more likely to be a problem.

A simpler alternative relies on the observation that the number of pieces in the string can never be more than the length of the string (unless InterSystems invents a half-byte delimiter;)

$p(x,delimiter,n,$l(x))

Another alternative, which is at least easy to read, is to use a constant that represents the maximum string length of the system:

$p(x,delimiter,n,%maximumStringLength)
Personal tools