将字符串解析为 D 中的标记

Parsing a string into tokens in D

我正在尝试在 D 中执行一些文件 I/O,但卡住了。我正在尝试读取数据文件并将字符串解析为对象的各种参数。我确实看到了一个关于堆栈溢出的例子,但我并不真正理解他们在做什么——但我熟悉如何在 Java 中做到这一点,并且有点熟悉如何在 C++ 中解析字符串。

我想要做的是获取一个字符串 Country,Exports,Trade Balance,Year,Population,Geographical Area 并用逗号将其分成单独的字符串。

这是目前为止的内容。我尝试使用 chomp() 作为 chomp(line, ",") 但它没有用。 4

import std.stdio;
import std.file;
import std.string;

void main(string[] args)
{
if (exists("source/data.txt")){
    File file = File("source/data.txt", "r");

    while (!file.eof()) 
    {
      string line = chomp(file.readln());
      writeln(line);
    }

} else {
    writeln("No such file here...");
}
}

我想你正在寻找 split or splitter