|
|
|||||||
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,","))] |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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... |
||||||||
|
|
|||||||
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? |
||||||||
|
|
|||||||
Nice way to remove dupes in a string. |
||||||||
|
|
|||||||
Quote: Richard, can you post some example code? |
||||||||
|
|
|||||||
These UDFs take advantage of some of the split join techniques... SNVerify() Replace() Any help? |
||||||||
|
|
|||||||
jim, is there actually what you are after? richie had a clean general example and you ask for example after that... |
||||||||
|
|
|||||||
Jooel, yes this is the kind of stuff I was hoping for. I asked for an example of how to use the code. |
||||||||
|
|
|||||||
well, place any string in $s and any character in $c and it will remove the dublicates. |
||||||||
|
|
|||||||
Quote: 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() A couple of examples
[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] |
||||||||
|
|
|||||||
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! |
||||||||
|
|
|||||||
From PostPrep Code: ; $f contains all file text. Replace characters "&", "<", and ">" with non-printing |
||||||||
|
|
|||||||
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(). |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
to quote a wise contributer around here.... "hmmm..." |
||||||||
|
|
|||||||
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:
|