home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / apl / 1239 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.1 KB  |  36 lines

  1. Newsgroups: comp.lang.apl
  2. Path: sparky!uunet!s5!hui
  3. From: hui@fid.morgan.com (Roger Hui)
  4. Subject: Re: A verb to trim spaces from a string
  5. Message-ID: <1992Dec12.211816.25135@fid.morgan.com>
  6. Organization: Morgan Stanley & Co., New York, NY
  7. References: <memo.805450@cix.compulink.co.uk>
  8. Date: Sat, 12 Dec 1992 21:18:16 GMT
  9. Lines: 25
  10.  
  11. Paul Moore writes:
  12.  
  13. >I am looking for a J verb which will take a string and remove all
  14. >leading and trailing whitespace from it. I have tried various
  15. >approaches, and I really cannot believe it is as hard as I'm finding
  16. >it...
  17. >
  18. >Specifically, I'm after 3 verbs
  19. >
  20. >    c ltrim str     Remove all occurrences of character c from
  21. >                    the start of str.
  22. >    c rtrim str     Remove all occurrences of character c from
  23. >                    the end of str.
  24. >    c trim str      Remove all occurrences of character c from
  25. >                    both ends of str.
  26. >
  27. >For the monadic cases, assume c is ' '.
  28.  
  29. ltrim =. ' '&$: : (+./\ @:~: # ])
  30. rtrim =. ' '&$: : (+./\.@:~: # ])
  31. trim  =. ' '&$: : ((+./\ *. +./\.)@:~: # ])
  32. ______________
  33.  
  34. Roger Hui
  35.  
  36.