Page 1 of 2 12>
Topic Options
#146412 - 2005-08-25 03:30 AM Ascan() Enhancement
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4482
Loc: USA
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.

Top
#146413 - 2005-08-25 02:11 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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.
_________________________
!

download KiXnet

Top
#146414 - 2005-08-25 04:36 PM Re: Ascan() Enhancement
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
InArray() perhaps.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146415 - 2005-08-25 07:24 PM Re: Ascan() Enhancement
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4482
Loc: USA
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).
Top
#146416 - 2005-08-25 10:24 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
I don't like the idea of having multiple optional parameters.
_________________________
!

download KiXnet

Top
#146417 - 2005-08-25 10:35 PM Re: Ascan() Enhancement
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146418 - 2005-08-25 10:47 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
no.
I understand that at some point and some place regExp engine for kixtart is introduced but this surely is not the place.
_________________________
!

download KiXnet

Top
#146419 - 2005-08-25 10:49 PM Re: Ascan() Enhancement
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4482
Loc: USA
So what's wrong with multiple optional args? I mean its not like this would be the first time its ever been done.
Top
#146420 - 2005-08-25 10:50 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
too confusing.
_________________________
!

download KiXnet

Top
#146421 - 2005-08-25 10:56 PM Re: Ascan() Enhancement
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4482
Loc: USA
LOL! Come on...If anyone can make it through Messagebox(), I think they might be able figure this one out too.
Top
#146422 - 2005-08-26 09:49 AM Re: Ascan() Enhancement
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
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.

Top
#146423 - 2005-08-26 01:28 PM Re: Ascan() Enhancement
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
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

Top
#146424 - 2005-08-26 01:34 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
well...
if instr can find a number in integer value, then the udf can too.
_________________________
!

download KiXnet

Top
#146425 - 2005-08-26 01:46 PM Re: Ascan() Enhancement
Ruud van Velsen Offline
Developer
*****

Registered: 1999-05-06
Posts: 359
Loc: Amsterdam, The Netherlands
Mmm, can someone please post a clear example of the functionality that you are looking for here?

What exactly is an 'inexact search'?

Ruud

Top
#146426 - 2005-08-26 01:51 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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
_________________________
!

download KiXnet

Top
#146427 - 2005-08-26 07:27 PM Re: Ascan() Enhancement
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11577
Loc: CA
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.
Top
#146428 - 2005-08-26 08:49 PM Re: Ascan() Enhancement
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
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.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146429 - 2005-08-26 09:07 PM Re: Ascan() Enhancement
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
so, to use regular expressions in kix, the data needs to be built inside array and then queried via ascan?
doh.
_________________________
!

download KiXnet

Top
#146430 - 2005-08-26 10:20 PM Re: Ascan() Enhancement
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Eh, that is NOT what I said! Regular expressions could be added to other commands/functions as well.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#146431 - 2005-08-26 10:26 PM Re: Ascan() Enhancement
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4482
Loc: USA
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?

Top
Page 1 of 2 12>


Moderator:  Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 142 anonymous users online.
Newest Members
KatieQuinn, Brennnnn, MKubicsek, xguixa, mdress
17681 Registered Users

Generated in 0.043 seconds in which 0.012 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org