Page 1 of 1
Bug(?) with gettoken(...,'count',...)
Posted: 16 Apr 2025 11:36
by PeterH
gettoken('\\NAS\share', 4, '\') returns 'share' - that's expected.
gettoken('\\NAS\share', 'count', '\') returns 2! It ignores the first empty tokens!
For me this is very strange, I think 'count' should return 4, including the empty tokens.
In other words: the count of
tokens is 4; the count of
tokens with a value is 2.
My problem: I (often!) need the real = full count of tokens for tokenlists!
And my string can be like '\\NAS\share', or like 'd:\xy'. Hard to handle.
Used for a report(), then needed to interpret the result. Each single line...
Re: Bug(?) with gettoken(...,'count',...)
Posted: 16 Apr 2025 11:45
by jupe
I'm not in front of a PC at the moment, but I am pretty sure that gpc can get a component count that might be better to use when you are dealing solely with paths.
Re: Bug(?) with gettoken(...,'count',...)
Posted: 16 Apr 2025 11:51
by highend
This has always? been the case that leading and trailing empty tokens were cut off.
This will lead to many "broken" scripts if this will be changed...
Re: Bug! with gettoken(...,'count',...)
Posted: 17 Apr 2025 11:19
by PeterH
@jupe Thanks! Your tip is just the way for me to go!
Seems over the years I forgot about GPC and so used GetToken.
@highend @Don At least there is one

- either in the function or the documentation!
There are 3 counts that could be asked for:
count of [all] tokens
count of empty tokens
count of non-empty tokens
I'm convinced that expected for 'count' is 'all'!
If it's not meant this way, it at least must be
documented, best in
bold and underlined.
And better: also add 3 new codewords: cnt, cnte, cntne (cnt could be cnta) for the 3 options.
If not: at least add cnta or countall - I'm convinced that is what's needed/used most.
And for people still using it for paths, a tip at the begin of gettoken()-doku:
For use on PATHs: use GPC()
Re: Bug(?) with gettoken(...,'count',...)
Posted: 24 Apr 2025 14:17
by admin
Agreed. I will add countall.
Re: Bug(?) with gettoken(...,'count',...)
Posted: 24 Apr 2025 14:25
by PeterH
Re: Bug(?) with gettoken(...,'count',...)
Posted: 24 Apr 2025 15:26
by admin
Decided to do it via the flags arg. Just a detail.
Re: Bug(?) with gettoken(...,'count',...)
Posted: 24 Apr 2025 17:30
by PeterH
A bit a matter of 'taste'...
I'd think: if I want count and can just select between 'count' and 'countall', it's a "direct" solution.
If I'd want count/all, and I have to select 'count' and also a flag - I'd think it's not so fine / intuitive.
The problem is that nowadays nobody has reason to expect the current way 'count' works - I think it's pure history from before we hat GPC?
Re: Bug(?) with gettoken(...,'count',...)
Posted: 24 Apr 2025 18:07
by admin
I agree, but I cannot change it without breaking old code.