Multisplit: Difference between revisions
Returned back correct D version and put correct output in task condition.
(add Ada) |
(Returned back correct D version and put correct output in task condition.) |
||
Line 5:
'''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.
Test your code using the input string “<code>a!===b
For these inputs the string should be parsed as <code>a
=={{header|Ada}}==
Line 98:
=={{header|D}}==
string[] multiSplit(in string s, string[] divisors) {
string[] result;
auto rest = s.idup;
if (p[1].empty || rest.empty) // divisor is not found OR it was last in string
break;
}▼
result.length+= 1;▼
▲ if (done) {
result[$ - 1]= rest.idup;▼
▲ return result;
▲ rest= t[2];
}
if (!rest.empty) {
return result;
}
void main() {
auto s = "a!===b
auto divs = ["==", "!=", "="];
auto lst = multiSplit(s, divs);
Line 135 ⟶ 131:
foreach (i, p; lst) {
write(p);
▲ }
}
writeln();
}
▲}</lang>
</lang>
Output (separators are enclosed in curlies):
<pre>a! {==}
=={{header|F_Sharp|F#}}==
|