Multisplit: Difference between revisions

Rewrote task description
(→‎Not using RE's: Handle edge cases consistently)
(Rewrote task description)
Line 1:
{{draft task}}It is often necessary to split a string into pieces based on several different (potentially multi-character) separator strings, while still retaining the information about which separators were present in the input. This is particularly useful when doing small parsing tasks.
{{draft task}}Code to split string with several separators.<br>
 
Input: string, list of separators<br>
Write code to demonstrate this. The function (or procedure or method, as appropriate) should take an input string and an ordered collection of separator strings, and split the string into pieces representing the various substrings. Note that the order of the separators is significant; where there would otherwise be an ambiguity as to which separator to use at a particular point (e.g., because one separator is a prefix of another) the first separator in the collection should be used. The result of the function should be an ordered sequence of substrings.
Output: [Sub0, [Sep0Num, Sep0Pos], Sub1, [Sep1Num, Sep1Pos], ..., SubN]<br>
 
Note: Sub - substring, SepNum - separator number in input list, SepPos - separator position in input string.<br>
'''Extra Credit:''' include match information that indicates which separator was matched at each separation point and where in the input string that separator was matched.
Input order of separators is important: they are considered in that order.
 
Test your code using the input string “<code>a!===b=!=c</code>” and the separators “<code>==</code>”, “<code>!=</code>” and “<code>=</code>”.
 
=={{header|J}}==
Anonymous user