Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,25 @@
import std.stdio, std.file, std.string;
void main() {
deleteLines("deleteline_test.txt", 1, 2);
}
void deleteLines(string name, int start, int num)
in {
assert(start > 0, "Line counting must start at 1");
} body {
start--;
if (!exists(name) || !isFile(name))
throw new FileException("File not found");
auto lines = readText(name).splitLines();
if (lines.length < start + num)
throw new Exception("Can't delete lines past the end of file!");
auto f = File(name, "w");
foreach (int i, line; lines) {
if (start > i || i >= start + num)
f.writeln(line);
}
}