Anonymous user
Multisplit: Difference between revisions
Undo revision 106291 by Vincent (talk) This is still disputed in the talk page and should not be in the task description yet
(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=!=c
For these inputs the string should be parsed as <code>a !=
=={{header|Ada}}==
Line 98:
=={{header|D}}==
<lang d>import std.stdio, std.array, std.algorithm;▼
<lang d>▼
▲import std.stdio, std.array, std.algorithm;
string[] multiSplit(in string s, string[] divisors) {
if (s.empty)▼
return [];▼
string[] result;
auto rest = s.idup;
auto
bool
foreach (div; divisors) {
rest = p[2];▼
auto maybe= find(rest, div);
if (maybe.length > best.length) {
best= maybe;
delim= div;
done= false;
}▼
}
} else {
auto t= findSplit(rest, delim);
result[$ - 1]= t[0].idup;
}
}
▲ result.length += 1;
▲ result[$ - 1] = rest.idup;
▲ }
}
void main() {
auto s = "a!===b=!=c
auto divs = ["==", "!=", "="];
auto lst = multiSplit(s, divs);
Line 131 ⟶ 135:
foreach (i, p; lst) {
write(p);
▲ }
}
writeln();
Output (separator locations indicated by braces):
▲<pre>a! {==} =b {!=} c! {=} d</pre>
=={{header|F_Sharp|F#}}==
|