Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!uunet!s5!hui
From: hui@fid.morgan.com (Roger Hui)
Subject: Re: A verb to trim spaces from a string
Message-ID: <1992Dec12.211816.25135@fid.morgan.com>
Organization: Morgan Stanley & Co., New York, NY
References: <memo.805450@cix.compulink.co.uk>
Date: Sat, 12 Dec 1992 21:18:16 GMT
Lines: 25

Paul Moore writes:

>I am looking for a J verb which will take a string and remove all
>leading and trailing whitespace from it. I have tried various
>approaches, and I really cannot believe it is as hard as I'm finding
>it...
>
>Specifically, I'm after 3 verbs
>
>    c ltrim str     Remove all occurrences of character c from
>                    the start of str.
>    c rtrim str     Remove all occurrences of character c from
>                    the end of str.
>    c trim str      Remove all occurrences of character c from
>                    both ends of str.
>
>For the monadic cases, assume c is ' '.

ltrim =. ' '&$: : (+./\ @:~: # ])
rtrim =. ' '&$: : (+./\.@:~: # ])
trim  =. ' '&$: : ((+./\ *. +./\.)@:~: # ])
______________

Roger Hui

