Multisplit: Difference between revisions

Go solution
(Added C# solution.)
(Go solution)
Line 272:
 
<code>System.StringSplitOptions.None</code> specifies that empty strings should be included in the result.
=={{header|Go}}==
<lang go>package main
 
import (
"fmt"
"strings"
)
 
func ms(txt string, sep []string) (ans []string) {
for txt > "" {
sepMatch := ""
posMatch := len(txt)
for _, s := range sep {
if p := strings.Index(txt, s); p >= 0 && p < posMatch {
sepMatch = s
posMatch = p
}
}
ans = append(ans, txt[:posMatch])
txt = txt[posMatch+len(sepMatch):]
}
return
}
 
func main() {
fmt.Printf("%q\n", ms("a!===b=!=c", []string{"==", "!=", "="}))
}</lang>
Output:
<pre>
["a" "" "b" "" "c"]
</pre>
 
=={{header|Icon}} and {{header|Unicon}}==
1,707

edits