#146412 - 2005-08-25 03:30 AM
Ascan() Enhancement
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
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
|
|
|
|
#146419 - 2005-08-25 10:49 PM
Re: Ascan() Enhancement
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
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
|
|
|
|
#146421 - 2005-08-25 10:56 PM
Re: Ascan() Enhancement
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
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
Registered: 2000-01-24
Posts: 4946
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
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
|
|
|
|
Moderator: Lonkero, ShaneEP, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart
|
0 registered
and 628 anonymous users online.
|
|
|