代码之家  ›  专栏  ›  技术社区  ›  StillLearningToCode

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

  •  1
  • StillLearningToCode  · 技术社区  · 11 年前

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

    我想做的是拿一根绳子 Country,Exports,Trade Balance,Year,Population,Geographical Area 并用逗号将其分隔成单独的字符串。

    这是目前为止的情况。我尝试使用chomp()作为chomp(行,“,”),但没有成功。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...");
    }
    }
    
    1 回复  |  直到 11 年前
        1
  •  5
  •   shammah    11 年前

    我想你在找 split splitter