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

Things you’d like to miss in the future...
Forum rules
:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:

:info: Please include the following information:
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".

:warnred20: :warnred20: :warnred20: :warnred20: :warnred20: READ THIS AND DO IT!!! :warnred20: :warnred20: :warnred20: :warnred20: :warnred20:
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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

jupe
Posts: 3462
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: 14991
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: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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()

admin
Site Admin
Posts: 66541
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: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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

Post by PeterH »

:tup:

admin
Site Admin
Posts: 66541
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: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

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?

admin
Site Admin
Posts: 66541
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