import strutils
echo split("test","") # does not work, compiler crashes
import nre
echo "test".split(re"") # so works
This is mistake? It will be corrected in the future?Araq, Ok. Then, I think you just need to bring to the behavior of some natural language for the behavior in case of empty separator. In some languages it is permissible:
javascript: console.log("test".split("")); [ 't', 'e', 's', 't' ]
julia: println(split("test","")) SubString{ASCIIString}["t","e","s","t"]
powershell: echo ("test" -split "") String[] [t, e, s, t]
php: print_r(str_split("test")); Array([0] => t,[1] => e,[2] => s,[3] => t)
perl: print join(':', split(//, 'test')), "\n"; t:e:s:t
in others: C # and blank or null separator is simply ignored, in python it causes a compilation error.
PS: Sorry for my English - it's google :-)
In Python:
>>> "asd qw asd".split("")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: empty separator
Let's adopt this behaviour.
dom96, I'm not against. Let there be an immediate error, it's better than an endless loop :-). And it should be clearly reflected in the documentation.
Besides for Nim, in principle, there is a sequester module which gives functionality of division of a line into symbols.
import sequester
echo explode("test") #@[t, e, s, t]