fork download
  1. iterator split*(s: string, sep: char): var string =
  2. var last = 0
  3. var res = newstring(256)
  4. assert('\0' != sep)
  5. if len(s) > 0:
  6. while last <= len(s):
  7. var first = last
  8. while last < len(s) and s[last] != sep:
  9. inc(last)
  10.  
  11. let len = last-first
  12. if len < 1:
  13. res.setLen 0
  14. else:
  15. res.setLen len
  16. copymem res[0], s[first].addr, L
  17. yield res ##yield substr(s, first, last-1)
  18. inc(last)
  19.  
  20. const str = """
  21. Hello
  22.  
  23.  
  24. hello
  25. hello
  26.  
  27. """
  28.  
  29. for x in str.split('\L'):
  30. echo x.len, " \"", x, '"'
  31.  
  32.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.nim(11, 9) Error: expression expected, but found 'let'
stdout
Standard output is empty