Jump to content

Multisplit: Difference between revisions

53 bytes removed ,  13 years ago
no need to mention output twice
m (wordliness)
(no need to mention output twice)
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. The task is to write code to demonstrate this.
 
Write code to demonstrate this. The function (or procedure or method, as appropriate) should take an input string and an ordered collection of separators, and split the string into pieces representing the various substrings. The order of the separators is significant: The delimiter order represents priority in matching. The first defined delimiter has the highest priority, so where there would 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. Delimiters can be reused. The resultoutput offrom the function should be an ordered sequence of substrings.
 
'''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.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.