#142217 - 2005-06-24 09:54 AM
Re: Join - Split syntax
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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
|
|
|
|
#142220 - 2005-06-24 07:36 PM
Re: Join - Split syntax
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
These UDFs take advantage of some of the split join techniques...
SNVerify() Replace()
Any help?
|
Top
|
|
|
|
#142224 - 2005-06-27 12:51 PM
Re: Join - Split syntax
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
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
- $s=udfTrim($s," ") ; remove redundant spaces from string
- $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
|
|
|
|
#142226 - 2005-06-27 07:35 PM
Re: Join - Split syntax
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
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
|
|
|
|
#142228 - 2005-06-28 01:32 AM
Re: Join - Split syntax
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
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
|
|
|
|
#142230 - 2005-06-28 02:49 AM
Re: Join - Split syntax
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
to quote a wise contributer around here....
"hmmm..."
|
Top
|
|
|
|
#142231 - 2005-06-28 03:14 AM
Re: Join - Split syntax
|
Lonkero
KiX Master Guru
Registered: 2001-06-05
Posts: 22346
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
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 507 anonymous users online.
|
|
|