home ~ projects ~ socials

Split A Neovim String In A Lua Script

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 --