PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Case insensitive DIM(FIND str$...)  (Read 990 times)

James Zukowski

  • Diamond Member
  • *****
  • Posts: 172
    • View Profile
Case insensitive DIM(FIND str$...)
« 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!
James Zukowski
Programmer / ERP Analyst
Beauty Enterprises, Inc.
150 Meadow St.
Hartford, CT 06114
860.296.9303  Ext 231

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3406
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Case insensitive DIM(FIND str$...)
« Reply #1 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



James Zukowski

  • Diamond Member
  • *****
  • Posts: 172
    • View Profile
Re: Case insensitive DIM(FIND str$...)
« Reply #2 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:
  • 0 - Exact match required (default; optional; current operation)
  • 1 - Exact match preferred, else first occurrence any case
  • 2 - First occurrence any case

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.
James Zukowski
Programmer / ERP Analyst
Beauty Enterprises, Inc.
150 Meadow St.
Hartford, CT 06114
860.296.9303  Ext 231

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3406
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Case insensitive DIM(FIND str$...)
« Reply #3 on: June 14, 2019, 03:57:50 PM »
Why not just use a memory file, it would allow you specify a case insensitive key.

James Zukowski

  • Diamond Member
  • *****
  • Posts: 172
    • View Profile
Re: Case insensitive DIM(FIND str$...)
« Reply #4 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).
James Zukowski
Programmer / ERP Analyst
Beauty Enterprises, Inc.
150 Meadow St.
Hartford, CT 06114
860.296.9303  Ext 231

Mike King

  • Administrator
  • Diamond Member
  • *****
  • Posts: 3406
  • Mike King
    • View Profile
    • PVX Plus Technologies
Re: Case insensitive DIM(FIND str$...)
« Reply #5 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

->