Page 1 of 1 1
Topic Options
#142213 - 2005-06-23 12:03 AM Join - Split syntax
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
I recall seeing some pretty nifty Join(Split... code in a few scripts. I'd like to see them documented somewhere, b/c I could never seem to find them when I need it nor am I completely straight on what the limitations of them are.

For instance, can I reference/return the ubound element of split'd array in one short line of code?

Something like this: Code:
 Split($MyString,",")[Ubound(Split($MyString,","))] 

_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#142214 - 2005-06-23 12:17 AM Re: Join - Split syntax
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
yes, you can do that.
but it's thought to be resource hog and thus almost never used.
with small string, it would not at all but with larger data and huge loops, it counts for lots of seconds.
_________________________
!

download KiXnet

Top
#142215 - 2005-06-23 12:28 AM Re: Join - Split syntax
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Post some code man! Any join/split tricks you've got.(You've only 92 to go.) I can see where the double split would kill performance in a massive loop.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#142216 - 2005-06-23 12:49 AM Re: Join - Split syntax
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
there is no tricks really...
join is simple thing, so is split.
can't understand what you mean with tricks.
and really, I only have 90...
_________________________
!

download KiXnet

Top
#142217 - 2005-06-24 09:54 AM Re: Join - Split syntax
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Hmmm... Join / Split tricks...

Ok, here's one that I use quite often:
Code:
While InStr($s,$c+$c) $s=Join(Split($s,$c+$c),$c) Loop


Useful, eh?

Top
#142218 - 2005-06-24 01:40 PM Re: Join - Split syntax
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
Nice way to remove dupes in a string.
_________________________
There are two types of vessels, submarines and targets.

Top
#142219 - 2005-06-24 05:22 PM Re: Join - Split syntax
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Quote:

Hmmm... Join / Split tricks...

Ok, here's one that I use quite often:
Code:
While InStr($s,$c+$c) $s=Join(Split($s,$c+$c),$c) Loop


Useful, eh?




Richard, can you post some example code?
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#142220 - 2005-06-24 07:36 PM Re: Join - Split syntax
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
These UDFs take advantage of some of the split join techniques...

SNVerify()
Replace()

Any help?

Top
#142221 - 2005-06-24 09:56 PM Re: Join - Split syntax
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
jim, is there actually what you are after?
richie had a clean general example and you ask for example after that...
_________________________
!

download KiXnet

Top
#142222 - 2005-06-24 11:10 PM Re: Join - Split syntax
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Jooel, yes this is the kind of stuff I was hoping for. I asked for an example of how to use the code.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#142223 - 2005-06-24 11:32 PM Re: Join - Split syntax
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
well, place any string in $s and any character in $c and it will remove the dublicates.
_________________________
!

download KiXnet

Top
#142224 - 2005-06-27 12:51 PM Re: Join - Split syntax
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Quote:

Richard, can you post some example code?




It's really as simple as Jooel states. You would use it to remove redundant characters from strings such as spaces or blank lines in file text.

It's so useful that I have it as a UDF.
Code:
; udfTRIM()
;
; Remove repeated characters from string, also removes leading and trailing
; characters.
;
Function udfTrim($s,$c)
While InStr($s,$c+$c) $s=Join(Split($s,$c+$c),$c) Loop
If Left($s,1)=$c $s=SubStr($s,2) EndIf
If Right($s,1)=$c $s=Left($s,-1) EndIf
$udfTrim=$s
EndFunction



A couple of examples
  1. $s=udfTrim($s," ") ; remove redundant spaces from string
  2. $sFileData=udfTrim($sFileData,@CRLF) ; remove blank lines from data


[edit]Oops - removed the leading/trailing stuff as it didn't work for all cases.[/edit]

[edit]Updated leading/trailing stuff - not as pretty as original but it works.[/edit]


Edited by Richard H. (2005-06-27 03:58 PM)

Top
#142225 - 2005-06-27 07:18 PM Re: Join - Split syntax
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Thanks for taking the time to post some examples. This is what I mean by knowing the limitations. Sometimes it's just not that obvious such as with second example. That's freakin' awesome!
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#142226 - 2005-06-27 07:35 PM Re: Join - Split syntax
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
From PostPrep

Code:
  ; $f contains all file text. Replace characters "&", "<", and ">" with non-printing
; characters, then split into an array of LINES. Hiding the replaced chars prevents
; treating them during the HTML processing
 
$f=split(join(split(join(split(join(split($f,"&"),$1),"<"),$2),">"),$3),@crlf)



 

Top
#142227 - 2005-06-27 07:48 PM Re: Join - Split syntax
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
OT: Curios Doc, is this where $1 = chr(38) $2 = chr(60) ...

Otherwise, an interesting implementation. I still can't believe I never thought to split on @CRLF. I wrote a stupid udf to do file2array().
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#142228 - 2005-06-28 01:32 AM Re: Join - Split syntax
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
In another thread , I ran into another limitation which was splitting on chr(###) when ### is greater than 127. If you place the actual character in the split, it splits fine, but not with its chr() counterpart.
Top
#142229 - 2005-06-28 02:05 AM Re: Join - Split syntax
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
allen, actually...
did you investigate the reason for that?
like, did you have ascii set to on or something?
chr() should split fine. if not, report it.
_________________________
!

download KiXnet

Top
#142230 - 2005-06-28 02:49 AM Re: Join - Split syntax
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
to quote a wise contributer around here....

"hmmm..."

Top
#142231 - 2005-06-28 03:14 AM Re: Join - Split syntax
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
well, did a quick test and no, not a single one of them fail.
but, they kinda do.
if you don't set casesensitivity, kixtart uses double 7 bit chartable, kinda...
well, see for yourself:
Code:

;fill a string with all chars...
;then, let's split with them.
;if split fails, spit out what was that char it errored on.
$=setoption("casesensitivity","on")
for $ascii=1 to 255
$char=chr($ascii)
$charstring=""+$charstring+$char
if 1<>ubound(split($charstring,$char))
? "Character #" $ascii " (" $char ") failed the split test"
endif
next

get $

_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 186 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.064 seconds in which 0.032 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