Skip to main content

String Functions, continued

$Piece has additional features. $Piece can return a range of pieces, rather than a single piece. It can return pieces from the same string based on different delimiters. $Piece returns the empty string if there's an empty piece (nothing before the first delimiter, or two delimiters in a row).

$Piece is important because it allows you to use a single string that contains multiple substrings, with a special delimiter character (such as ^) to separate them. The large string acts as a record, and the substrings are its fields. Also, note that $Length has a piece-oriented variant: it returns the number of pieces in a string based on a delimiter.

Terminal


USER>write $piece("slice of cheese pizza", " ", 1, 2)
slice of
USER>write $piece("slice of cheese pizza", " ", *-1, *)
cheese pizza
USER>write $piece("slice of cheese pizza", "i", 2)
ce of cheese p
USER>write $piece("slice of cheese pizza", "z", 2)

USER>set city = $piece("One Memorial Drive^Cambridge^MA^02142", "^", 2)

USER>write city
Cambridge
USER>write $length("slice of cheese pizza", " ")
4
USER>
FeedbackOpens in a new tab