Skip to main content

Delimited Strings

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).

println "using string: slice of pizza"
println "3rd piece = ", piece("slice of pizza", " ", 3)
println "1st and 2nd pieces = ", piece("slice of pizza", " ", 1, 2)
println "2nd piece by i = ", piece("slice of pizza", "i", 2)
println "2nd (empty) piece by z = ", piece("slice of pizza", "z", 2)
println "count of pieces = ", len("slice of pizza", " ")
address = "One Memorial Drive^Cambridge^MA^02142"
city = piece(address, "^", 2)
println "city = ", city
println "MA starts at position #", InStr(address, "^MA^")+1 ' one past ^
FeedbackOpens in a new tab