Page 1 of 1 1
Topic Options
#136808 - 2005-03-30 10:05 PM Make JOIN() from left OR right.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just ran into a thingy where I could have used the following:

The Join() function takes a third optional (positive) number indicating the number of array elements to join (from the beginning of the array) ...

Was thinking would be nice to be able to specify a negative number, indicating that the join works from the end (or tail-end of the array), inward. Kinda like:

Code:

break on

$array = 1,2,3,4

?"val=" join($array, "-", 2) ; produces 1-2

?"val=" join($array, "-", -2) ; currently produces 1-2-3-4, maybe have it do 3-4 instead ?



Anyway - really could have used this today - I know there are ways to achieve the desired result without this, but since negative numbers in the third argument aint supported anyways, doesn't hurt to think aloud.

-Shawn

Top
#136809 - 2005-03-30 10:17 PM Re: Make JOIN() from left OR right.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja.
if not too hard to implement, there is use for it.
_________________________
!

download KiXnet

Top
#136810 - 2005-03-30 11:10 PM Re: Make JOIN() from left OR right.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Just to drive this home a little more, the requirement I had was in parsing SID's to use with the SID2USER utility ... as we know, SID's look like this:

S-1-5-21-3189408152-3842477530-4120753002-500

but sid2user doesn't like that format, it wants the sid in this format:

sid2user \\server 5 21 3189408152 3842477530 4120753002 500

so wanted to do a bit of split/joining as follows:

?"sid=" join(split("S-1-5-21-3189408152-3842477530-4120753002-500","-")," ", -6)

Minus six being that last 6 elements of the sid, but can't do unfortunately. Ended up just checking for UBound() and doing a long bit of appending of array elements and spaces ...

-Shawn

Top
#136811 - 2005-03-30 11:33 PM Re: Make JOIN() from left OR right.
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I had this come up a little while ago, where i only wanted the last X number of array items in a join statement.

joins a join($array,"-",-4) would have been better than this....

Code:

Function reversejoin($array,$d,$n)
If UBound($array)-$n > -1
For $N = UBound($array)-$n To UBound($array)
$reversejoin = "" + $reversejoin + $d + $array[$N]
Next
Else
$reversejoin = Join($array,$d)
EndIf
If SubSTR($reversejoin,1,1) = $d $reversejoin = SubSTR($reversejoin,2) EndIf
EndFunction


Top
Page 1 of 1 1


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

Who's Online
0 registered and 837 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.055 seconds in which 0.026 seconds were spent on a total of 12 queries. Zlib compression enabled.

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