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:

LanguageSplit without parametersSplit with parameter
Python''.split()=[]''.split(',')=['']
Ruby''.split()=[]''.split(',')=[]
JavaScript''.split()=['']''.split(',')=['']
PHPN/Aexplode(',', '')=array(0=>'')
JavaN/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

Popular posts from this blog

Web application framework comparison by memory consumption

Trac Ticket Workflow

Shellcode detection using libemu