Bug(?) with gettoken(...,'count',...)

Things you’d like to miss in the future...
Post Reply
PeterH
Posts: 2811
Joined: 21 Nov 2005 20:39
Location: Germany

Bug(?) with gettoken(...,'count',...)

Post by PeterH »

gettoken('\\NAS\share', 4, '\') returns 'share' - that's expected. :tup:
gettoken('\\NAS\share', 'count', '\') returns 2! It ignores the first empty tokens! :shock: :?:

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...
Win11 Pro 23H2 Gerrman

jupe
Posts: 3192
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Bug(?) with gettoken(...,'count',...)

Post 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.

highend
Posts: 14106
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Bug(?) with gettoken(...,'count',...)

Post 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...
One of my scripts helped you out? Please donate via Paypal

PeterH
Posts: 2811
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Bug! with gettoken(...,'count',...)

Post 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 :bug: - 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()
Win11 Pro 23H2 Gerrman

admin
Site Admin
Posts: 63404
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug(?) with gettoken(...,'count',...)

Post by admin »

Agreed. I will add countall.

PeterH
Posts: 2811
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Bug(?) with gettoken(...,'count',...)

Post by PeterH »

:tup:
Win11 Pro 23H2 Gerrman

admin
Site Admin
Posts: 63404
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug(?) with gettoken(...,'count',...)

Post by admin »

Decided to do it via the flags arg. Just a detail.

PeterH
Posts: 2811
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Bug(?) with gettoken(...,'count',...)

Post 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?
Win11 Pro 23H2 Gerrman

admin
Site Admin
Posts: 63404
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Bug(?) with gettoken(...,'count',...)

Post by admin »

I agree, but I cannot change it without breaking old code.

Post Reply