Dan Bron wrote;
> If your code can produce the same results as the following in all cases,
> it is correct:
>
> load 'strings'
> fw2dl =: [: ; [: (dltb@:}: , {:)&.> e.&(10 9{a.) <;.2 ] NB. Assume
> y ends with LF
I belive trim, as defined below, is equivalent to fw2dl for the cases where
y ends with LF. If not, I'd be very interested in the case where this does
not hold.
NB. other SPACE DELIM
s=:0 10#:10*".;._2]0 :0
2.1 0.0 1.1 NB. 0: skipping initial whitespace
2.2 0.3 1.2 NB. 1: found delimiter
2.0 3.2 1.2 NB. 2: found non-whitespace
2.2 3.0 1.1 NB. 3: potentially trailing whitespace
)
trim=: (1;s;(a.=' ')+2*a.e.LF,TAB)&;:
P.S. this post is meant to be read in a fixed-width font. My
broken email client is not rendering it that way, but past
experience leads me to believe that it will probably be distributed
in a fashion which lends itself towards that end. If not, perhaps
pasting the code into J will be adequate...
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm