Multisplit: Difference between revisions
Content added Content deleted
(added MiniScript example) |
(add SenseTalk examples) |
||
Line 1,730: | Line 1,730: | ||
("a" "!=" "" "==" "b" "=" "" "!=" "c") |
("a" "!=" "" "==" "b" "=" "" "!=" "c") |
||
</pre> |
</pre> |
||
=={{header|SenseTalk}}== |
|||
<lang sensetalk> |
|||
set source to "a!===b=!=c" |
|||
set separators to ["==", "!=", "="] |
|||
// first approach, using line delimiters |
|||
put each line delimited by separators of source |
|||
// second approach, using a pattern |
|||
set source to "a!===b=!=c" |
|||
set separatorPattern to <"==" or "!=" or "="> |
|||
put source split by separatorPattern |
|||
// and show the separators that were found, for extra credit: |
|||
put each occurrence of separatorPattern in source |
|||
</lang> |
|||
Output: |
|||
<lang sensetalk>(a,,b,,c) |
|||
(a,,b,,c) |
|||
(!=,==,=,!=)</lang> |
|||
Explanation: |
|||
Lines are delimited by an array of separator strings, normally [CRLF, LF, CR, lineSeparator(0x2028), paragraphSeparator(0x2029)]. Supplying an alternate set of delimiters lets us split a string by a different (ordered) set of strings. |
|||
SenseTalk's pattern language lets us define a pattern (a regex) which can then be used to split the string and also to display the actual separators that were found. |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |