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
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.
damn all that to parse a basic file 😄
I like it
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
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.