split function behavior differences
A little note from my debugging experience. Split function works differently and I would say unexpectedly for empty string in different programming languages, and it can cause difficult to find bugs (especially if you use a lot of languages simultaneously).
I've created a table with the popular programming languages:
I've created a table with the popular programming languages:
Language | Split without parameters | Split with parameter |
---|---|---|
Python | ''.split()=[] | ''.split(',')=[''] |
Ruby | ''.split()=[] | ''.split(',')=[] |
JavaScript | ''.split()=[''] | ''.split(',')=[''] |
PHP | N/A | explode(',', '')=array(0=>'') |
Java | N/A | "".split(",")={""} |
C# | "".Split()={""} | "".Split(',')={""} |
As you can see sometimes it returns empty array, but sometimes an array with the one empty element. So please be careful with the split operation :)
Comments
Post a Comment