RosettaCodeData/Task/Multisplit/Pike/multisplit.pike
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

17 lines
447 B
Text

string input = "a!===b=!=c";
array sep = ({"==", "!=", "=" });
array result = replace(input, sep, `+("\0", sep[*], "\0"))/"\0";
result;
Result: ({ "a", "!=", "", "==", "b", "=", "", "!=", "c" })
int pos = 0;
foreach(result; int index; string data)
{
if ((<"==", "!=", "=">)[data])
result[index] = ({ data, pos });
pos+=sizeof(data);
}
result;
Result: ({"a", ({"!=", 1}), "", ({"==", 3}), "b", ({"=", 6}), "", ({"!=", 7}), "c"})