AllenAdministrator
(KiX Supporter)
2005-08-25 03:30 AM
Ascan() Enhancement

Ascan is limited to exact searches within a array. I think it would be useful to have an optional mode which allows you to do an "in-exact" search, much like the way Excel's find does it.

I dug around to see if anyone has requested this and about the only thing I found was this thread.


LonkeroAdministrator
(KiX Master Guru)
2005-08-25 02:11 PM
Re: Ascan() Enhancement

Ainstr()?
right?

a instr that is capable of searching array?
and actually would work kinda as:
instr(join($array,"*"))

ja, I've missed that functionality sometimes.

what I would want to be enhanced too is the capability for ascan() to return all matches at once in KiXtart array.


Les
(KiX Master)
2005-08-25 04:36 PM
Re: Ascan() Enhancement

InArray() perhaps.

AllenAdministrator
(KiX Supporter)
2005-08-25 07:24 PM
Re: Ascan() Enhancement

InArray() or Ainst() would be fine, but my thought was to just add an optional parameter to Ascan($array, $findstr, $start, $length, $Exact/In-exactMode).

LonkeroAdministrator
(KiX Master Guru)
2005-08-25 10:24 PM
Re: Ascan() Enhancement

I don't like the idea of having multiple optional parameters.

Les
(KiX Master)
2005-08-25 10:35 PM
Re: Ascan() Enhancement

I don't like the ainst() (or ainstr()) name though. AFAIK "InStr" is short for "In String" so then "ainstr" would be what, "Array In String"?

I have no issue with adding a partial match parm but think it should go beyond that. Maybe here would be a good place to get regular expressions introduced. The optional parm for AScan() could be a regular expression.


LonkeroAdministrator
(KiX Master Guru)
2005-08-25 10:47 PM
Re: Ascan() Enhancement

no.
I understand that at some point and some place regExp engine for kixtart is introduced but this surely is not the place.


AllenAdministrator
(KiX Supporter)
2005-08-25 10:49 PM
Re: Ascan() Enhancement

So what's wrong with multiple optional args? I mean its not like this would be the first time its ever been done.

LonkeroAdministrator
(KiX Master Guru)
2005-08-25 10:50 PM
Re: Ascan() Enhancement

too confusing.

AllenAdministrator
(KiX Supporter)
2005-08-25 10:56 PM
Re: Ascan() Enhancement

LOL! Come on...If anyone can make it through Messagebox(), I think they might be able figure this one out too.

Richard H.Administrator
(KiX Supporter)
2005-08-26 09:49 AM
Re: Ascan() Enhancement

Following on from Lonk's suggestion, here's a UDF to do the job.

Note, no type checking of variables, use the optional delimiter if you have @CRLFs in the data.
Code:
Function udfStrInArray($aArray,$sSearch,Optional $sDelimiter)
Dim $iIndex
If Not VarType($sDelimiter) $sDelimiter=@CRLF EndIf

$udfStrInArray=(-1)

$aArray=Join($aArray,$sDelimiter)
$iIndex=InStr($aArray,$sSearch)

If $iIndex $udfStrInArray=UBound(Split(Left($aArray,$iIndex-1),$sDelimiter)) EndIf

Exit 0
EndFunction



This returns the array element that the (sub)string was found in, or "-1" if not found.


Witto
(MM club member)
2005-08-26 01:28 PM
Re: Ascan() Enhancement

What if
Code:

Break On

Dim $MyArray, $MySearch
$MyArray = 21,22,23,24,25,26,27,28,29
$MySearch = 6
? udfStrInArray($MyArray, $MySearch)

$MySearch = 2
? udfStrInArray($MyArray, $MySearch) ;would expect something like ("0,1,2,3,4,5,6,7,8")

ReDim $MyArray[4,1]
$MyArray[0,0]=21
$MyArray[0,1]=22
$MyArray[1,0]=23
$MyArray[1,1]=24
$MyArray[2,0]=25
$MyArray[2,1]=26
$MyArray[3,0]=27
$MyArray[3,1]=28
$MyArray[4,0]=29
$MyArray[4,1]=30
$MySearch = 6
? udfStrInArray($MyArray, $MySearch) ;would expect something like ("[2,1]")


Anyway, all respect for the UDF


LonkeroAdministrator
(KiX Master Guru)
2005-08-26 01:34 PM
Re: Ascan() Enhancement

well...
if instr can find a number in integer value, then the udf can too.


Ruud van Velsen
(Hey THIS is FUN)
2005-08-26 01:46 PM
Re: Ascan() Enhancement

Mmm, can someone please post a clear example of the functionality that you are looking for here?

What exactly is an 'inexact search'?

Ruud


LonkeroAdministrator
(KiX Master Guru)
2005-08-26 01:51 PM
Re: Ascan() Enhancement

someone may correct me but.
it's basically a instr() on each array element.

if array has:
$array = "ruud","les","jokeli"

this new functionality, say inArray(), would return on:
inArray($array,"e")

1, as it's the first element where "e" is present.


hope that's clean enough


NTDOCAdministrator
(KiX Master)
2005-08-26 07:27 PM
Re: Ascan() Enhancement

Sent Al a PM to check back here and provide a better example of what he's looking for. Not sure if he wants it to be "Fuzzy" search or what.

Les
(KiX Master)
2005-08-26 08:49 PM
Re: Ascan() Enhancement

My guess is he wants a substring match without any fuzz. I still think, since we have it cut open on the table, to add support for wildcards with regular expressions.

LonkeroAdministrator
(KiX Master Guru)
2005-08-26 09:07 PM
Re: Ascan() Enhancement

so, to use regular expressions in kix, the data needs to be built inside array and then queried via ascan?
doh.


Les
(KiX Master)
2005-08-26 10:20 PM
Re: Ascan() Enhancement

Eh, that is NOT what I said! Regular expressions could be added to other commands/functions as well.

AllenAdministrator
(KiX Supporter)
2005-08-26 10:26 PM
Re: Ascan() Enhancement

Lonks example is correct... and just for more info...

$array="YYYY","MM","DD"
$=ascan($array,"Y")

$ would equal -1 right now because there is no value "Y" in the array. With the fuzzy/in-exact results $ would return 0.

Does this help?


Ruud van Velsen
(Hey THIS is FUN)
2005-08-29 06:30 PM
Re: Ascan() Enhancement

Ok, I understand now and have added this functionality (i.e.: the option to have AScan do an InStr instead of an exact match) to beta 1 of 4.51.

The beta is on its way to the download sites as I type this...

Ruud


ShawnAdministrator
(KiX Supporter)
2005-08-29 06:39 PM
Re: Ascan() Enhancement

Password protected tokenized files .... very nice ;0)

AllenAdministrator
(KiX Supporter)
2005-08-29 06:48 PM
Re: Ascan() Enhancement

Great! Thanks Ruud.

AllenAdministrator
(KiX Supporter)
2005-08-31 06:09 PM
Re: Ascan() Enhancement

Hey Richard... I somehow overlooked the UDF you posted. Thanks for putting that together... but since its in ascan now, I'll probably never get to use it...

LonkeroAdministrator
(KiX Master Guru)
2005-08-31 06:16 PM
Re: Ascan() Enhancement

lol.
but that UDF indeed was nice.
I was too lazy to wrap it up but richie came and conquered