PxPlus User Forum

Main Board => Discussions => Wish List => Topic started by: James Zukowski on June 14, 2019, 11:05:49 AM

Title: Case insensitive DIM(FIND str$...)
Post by: James Zukowski on June 14, 2019, 11:05:49 AM
Is there a way to modify DIM(FIND str$...) [Format 6] to allow case insensitivity? Many times, we'll know the word we're looking for, but not necessarily whether it will be UPPER, lower, or Mixed case. Perhaps adding an optional argument to the function call would permit this.
It might also be useful for DIM(FIND min/max...).
Thanks!
Title: Re: Case insensitive DIM(FIND str$...)
Post by: Mike King on June 14, 2019, 03:13:03 PM
The issue would not be so much on the FIND but a potential issue if you had keys of "Mike", "MIKE" and "mike" -- which would the FIND return?

What you could do is spin through the array using the DIM(KEY array[index] ) to get the keys or use the FOR directive to walk through the elements as in:

Code: [Select]
0010 LET x$["John"]="Smith"
0020 LET x$["john"]="Jones"
0030 FOR n$ INDEX x${ALL}
0040 PRINT n$
0050 NEXT


Title: Re: Case insensitive DIM(FIND str$...)
Post by: James Zukowski on June 14, 2019, 03:29:51 PM
We're already doing the loop through to find what we want. I was just looking for a shorter method.

For the "potential issue": There could be several options:

Consider this:
Code: [Select]
dim x$[1:6]
x$[1]="Dog",x$[2]="Cat",x$[3]="Pig",x$[4]="Ant",x$[5]="Pig",x$[6]="Zebra"
print dim(find x$="Pig")
currently returns 3, not 5, even though that is a valid response as well.

For this discussion, I've been referring to straightforward arrays, not an Associated or JSON array. How this would apply to those situations, I'm not sure.
Title: Re: Case insensitive DIM(FIND str$...)
Post by: Mike King on June 14, 2019, 03:57:50 PM
Why not just use a memory file, it would allow you specify a case insensitive key.
Title: Re: Case insensitive DIM(FIND str$...)
Post by: James Zukowski on June 14, 2019, 04:16:46 PM
While that is certainly an alternative, and I have done that in the past as well, there are times when the sequence needs to be maintained (correspondence to a list box, for example).
Title: Re: Case insensitive DIM(FIND str$...)
Post by: Mike King on June 14, 2019, 04:29:24 PM
So just write the data with a sequence number as in:

OPEN (1) "*memory*;keydef=[1:1:4:B],[2:1:10:C]"
WRITE (1) 1, "Dog"
WRITE (1) 2, "Cat"
WRITE (1) 3, "Pig"
WRITE (1) 4, "Ant"
WRITE (1) 5, "Pig"
WRITE (1) 6, "Zebra"

Now you can access by number (primary key) or by name (kno=1) plus you could add additional columns to the record if required.  You can access this as follows:

->print rcd(1,key=4)
4
Ant

->print rcd(1,key="pig",kno=1)
3
Pig

->