1 USING: help.markup help.syntax kernel sequences strings ;
4 ARTICLE: "sequences-split" "Splitting sequences"
5 "Splitting sequences at occurrences of subsequences:"
21 "Splitting a string into lines:"
22 { $subsections string-lines }
23 "Replacing subsequences with another subsequence:"
24 { $subsections replace } ;
26 ABOUT: "sequences-split"
29 { $values { "seq" sequence } { "subseq" sequence } { "before" "a new sequence" } { "after" "a new sequence" } }
30 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
33 { $values { "seq" sequence } { "subseq" sequence } { "before-slice" slice } { "after-slice" slice } }
34 { $description "Splits " { $snippet "seq" } " at the first occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
37 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "before" "a new sequence" } { "after" "a new sequence" } }
38 { $description "Splits " { $snippet "seq" } " at the first occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs the pieces before and after the split." } ;
40 HELP: split1-when-slice
41 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "before-slice" slice } { "after-slice" slice } }
42 { $description "Splits " { $snippet "seq" } " at the first occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
45 { $values { "seq" sequence } { "subseq" sequence } { "before" "a new sequence" } { "after" "a new sequence" } }
46 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
48 HELP: split1-last-slice
49 { $values { "seq" sequence } { "subseq" sequence } { "before-slice" slice } { "after-slice" slice } }
50 { $description "Splits " { $snippet "seq" } " at the last occurrence of " { $snippet "subseq" } ", and outputs the pieces before and after the split as slices. If " { $snippet "subseq" } " does not occur in " { $snippet "seq" } ", then " { $snippet "before" } " is just " { $snippet "seq" } " and " { $snippet "after" } " is " { $link f } "." } ;
52 { split1 split1-slice split1-last split1-last-slice } related-words
55 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
56 { $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
57 { $examples { $example "USING: ascii kernel prettyprint splitting ;" "\"hello,world-how.are:you\" [ letter? not ] split-when ." "{ \"hello\" \"world\" \"how\" \"are\" \"you\" }" } } ;
59 HELP: split-when-slice
60 { $values { "seq" sequence } { "quot" { $quotation ( ... elt -- ... ? ) } } { "pieces" "a new array" } }
61 { $description "Splits " { $snippet "seq" } " at each occurrence of an element for which " { $snippet "quot" } " gives a true output and outputs an array of pieces as " { $link slice } "s. The pieces do not include the elements along which the sequence was split." } ;
64 { $values { "seq" sequence } { "indices" sequence } { "pieces" "a new array" } }
65 { $description "Splits a sequence at the given indices." }
68 "USING: prettyprint splitting ;"
69 "\"hello world\" { 3 6 } split-indices ."
70 "{ \"hel\" \"lo \" \"world\" }"
75 { $values { "seq" sequence } { "separators" sequence } { "pieces" "a new array" } }
76 { $description "Splits " { $snippet "seq" } " at each occurrence of an element of " { $snippet "separators" } " and outputs an array of pieces. The pieces do not include the elements along which the sequence was split." }
77 { $examples { $example "USING: prettyprint splitting ;" "\"hello world-how are you?\" \" -\" split ." "{ \"hello\" \"world\" \"how\" \"are\" \"you?\" }" } } ;
80 { $values { "seq" sequence } { "begin" sequence } { "newseq" "a new sequence" } { "?" boolean } }
81 { $description "Tests if " { $snippet "seq" } " starts with " { $snippet "begin" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "begin" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
84 { $values { "seq" sequence } { "begin" sequence } { "newseq" slice } { "?" boolean } }
85 { $description "Like " { $link ?head } ", except the resulting sequence is a " { $link slice } "." } ;
88 { $values { "seq" sequence } { "end" sequence } { "newseq" "a new sequence" } { "?" boolean } }
89 { $description "Tests if " { $snippet "seq" } " ends with " { $snippet "end" } ". If there is a match, outputs the subrange of " { $snippet "seq" } " excluding " { $snippet "end" } ", and " { $link t } ". If there is no match, outputs " { $snippet "seq" } " and " { $link f } "." } ;
92 { $values { "seq" sequence } { "end" sequence } { "newseq" slice } { "?" boolean } }
93 { $description "Like " { $link ?tail } ", except the resulting sequence is a " { $link slice } "." } ;
96 { $values { "seq" sequence } { "seq'" { $sequence string } } }
97 { $description "Splits a string along line breaks." }
99 { $example "USING: prettyprint splitting ;" "\"Hello\\r\\nworld\\n\" string-lines ." "{ \"Hello\" \"world\" }" }
103 { $values { "seq" sequence } { "old" sequence } { "new" sequence } { "new-seq" sequence } }
104 { $description "Replaces every occurrence of " { $snippet "old" } " with " { $snippet "new" } " in the " { $snippet "seq" } "." }
106 { $example "USING: io splitting ;"
107 "\"cool example is cool\" \"cool\" \"silly\" replace print"
108 "silly example is silly"