Hi Joe, I think this behaviour makes sense.
FileNameArray0 (that is, the
number of created substrings, not occurrences of the delimiter) is only 0, when there are no produced substrings. For example, if
FileNameOnly is blank (""), the result can only be blank -> 0 occurrences, 0 substrings produced:
Code: Select all
FileNameOnly:="" ; blank
StringSplit,FileNameArray,FileNameOnly,_
MsgBox,,debug StringSplit,FN0=%FileNameArray0% FN1=%FileNameArray1%
If the variable is not blank, and if the delimiter is not in the string, like in your example, you still get the original string in
FileNameArray1 (= test.pdf) - one string, split 0 times. Hence, the number of (sub-)strings in
FileNameArray0 is 1 (= the highest index number of the created pseudoarray - useful for looping).
Think of it this way: The next highest occurrence of the delimiter would be 1, for example in "test_1.pdf". Then, you already get 2 substrings. Accordingly, 2 delimiters will create 3 substrings...
0 delimiters found in no string ("" = blank) -> 0 substrings
0 delimiters found in a string -> 1 (sub-)string (original string)
1 delimiter found in a string -> 2 substrings (original split in two)
2 delimiters -> 3 substrings
3 -> 4
4 -> 5
etc.
This pattern makes kind of sense to me. The command/function takes a string and always returns the whole string input, just split by delimiters and without OmitChars. These are the only characters which get omitted - the rest of the string should not be omitted. And
FileNameArray0 always holds the highest used index of the created pseudoarray.
If there is no delimiter or character to omit to be found, you still have 1 string left that got split 0 times. I think your expectation that 0 should be returned in this case, makes much more sense with the
Instr() function, which returns 0, meaning
"not found" /
false, if there was no occurrence. But here you get the number of resulting strings instead...
I don't think that this behaviour has changed over time.