Processing split() function does not treat empty fields as elements
in
Programming Questions
•
1 year ago
I am trying to split() a very simply .csv file at all commas using the split function. There are some empty fields at the very end of some lines, which Processing is treating as simply not existing, rather than empty fields. Example:
String myString = "i expect, this to be, of length six,,,";
println(myString.split(",").length);
// prints "3", not "6"
Is this behaviour by design, or a bug? I've found inserting a character at the end of the line triggers the expected behaviour. Example:
String myString = "i expect, this to be, of length six,,,!";
println(myString.split(",").length);
// actually prints "6"
So it doesn't seem that Processing is ignoring blank fields altogether... Surely this kind of behaviour isn't by design?
1