Product Site

5.1.7.94. subWords

Returns an array containing all words within the substring of the receiving string that starts at the nth word and is up to length whitespace-delimited words. The n must be a positive whole number. If you omit n, it defaults to 1. If you omit length, it defaults to the number of remaining words in the receiving string. The strings in the returned array never have leading or trailing whitespace.
Example 5.128. String class — subWords method
"Now is the  time"~subWords         -->    .array~of("Now", "is", "the", "time")
"Now is the  time"~subWords(2,2)    -->    .array~of("is", "the")
"Now is the  time"~subWords(3)      -->    .array~of("the", "time")
"Now is the  time"~subWords(5)      -->    .array~new(0)

The subWords method is useful for iterating over the individual words in a string.
Example 5.129. String class — subWords method
    do word over source~subWords    -- extract all of the words to loop over
       say word
    end