On Sunday, 16 June 2019 at 22:47:14 UTC, Samir wrote:
I am trying to read from a text file using the following code:

import std.stdio;
import std.string;

void main() {
    File file = File("test.txt");
    string line;

    while (!file.eof()) {
        line = strip(file.readln());
        if (line[0] == '>') {         // line 10
        else {

and I get the following error AFTER the last line is processed:

core.exception.RangeError@readfile.d(10): Range violation
??:? _d_arrayboundsp [0x448efa]
??:? _Dmain [0x4459f7]

Any idea what I am doing wrong? When processing the if statement or writing the slice, am I inadvertently trying to read a non-existent line in the file?

Thanks in advance

stripping the last line could result in an empty line if it just has strippable characters?

Reply via email to