Beginner's Guide to Zig Part 14 - Opening and parsing a file

Поділитися
Вставка
  • Опубліковано 21 лис 2024

КОМЕНТАРІ • 3

  • @MuhammadHosny0
    @MuhammadHosny0 4 місяці тому

    damn all that to parse a basic file 😄
    I like it

  • @TheFreshMakerHD
    @TheFreshMakerHD 4 місяці тому

    The standard library has a cool 'tokenizeAny' function that allows you to specify a type, some data, and a series of delimiters. you can call it like this: var it = std.mem.tokenizeAny(u8, poem, " ,;
    !"); then you can loop through the it variable in a while loop: while (it.next()) |word| {...} . I believe this gives you some flexibility in determining whether to read a file by line or by loading it all into memory

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl  4 місяці тому

      I knew there were the tokenizer and iterators in the standard library, the example I'm showing here is already quite complicated and I wanted to keep it simpler and not show too many new things at once.
      A tokenizer probably would be better to use here as it doesn't actually require you to allocate memory in an arrayLIst for the lines.