home ~ socials ~ projects ~ rss

Split A Neovim String In A Lua Script

October 2024

Copied in, but needs to be tested

function split_string(str, delimiter) 
  local results = {}
  local from = 1
  local delim_from, delim_to = string.find(str, delimiter, from)
  while delim_from do
    table.insert(results, string.sub(str, from , delim_from-1))
    from  = delim_to + 1
    delim_from, delim_to = string.find(str, delimiter, from)
  end
  table.insert(results, string.sub(str, from))
  return results
end
end of line
Share link:
https://www.alanwsmith.com/en/2n/ab/ez/9d/?split-a-neovim-string-in-a-lua-script