System.out.println("neon.mems.cmu.edu/people/".split("/").length); // output is 2
I was doing some url processing. To my surprise I just got the result above. I thought the number of elements could be the number of splitters plus one.
I didn’t realize the last empty string(or just null) is cut off from the splitted array until now. I wonder if this is the case with every programming language.
No that’s not the case for every programming language and there is no universal specification so there is no reason it should be.
Go
Javascript
Type this in the console of your browser :
The result is
What you should do when a match is empty isn’t something obvious or inherent to the
splitconcept. A proof of that is that old Internet Explorer versions did remove those empty matches.