Tuesday, March 30, 2010

Splitting the Splitter

Here’s a cute little oafish trick that has helped me out more than a few times.  You run an inline Split/Array operation to mimic what the LISP cdr and cadr, etc. functions do, which is to pick out a logical subordinate within a string construct which represents a paired list (logically speaking).

myString = “1=Apple,2=Banana,3=Cherry,4=Grapes”

item2 = Split(Split(myString, “,”)(1), “=”)(1)


This will return “Banana”.  You can continue nesting (or un-nesting, if you will) obviously, but without error checking this can become quite dangerous.  But it is nice to see a use for something like this.  Now, if only there were a simple, easy way to mimic mapcar and apply as well.

No comments:

Post a Comment