RosettaCodeData/Task/Strip-control-codes-and-extended-characters-from-a-string/D/strip-control-codes-and-extended-characters-from-a-string.d
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

19 lines
510 B
D

import std.traits;
S stripChars(S)(S s, bool function(dchar) pure nothrow mustStrip)
pure nothrow if (isSomeString!S) {
S result;
foreach (c; s) {
if (!mustStrip(c))
result ~= c;
}
return result;
}
void main() {
import std.stdio, std.uni;
auto s = "\u0000\u000A abc\u00E9def\u007F";
writeln(s.stripChars( &isControl ));
writeln(s.stripChars( c => isControl(c) || c == '\u007F' ));
writeln(s.stripChars( c => isControl(c) || c >= '\u007F' ));
}