"delete extra blanks" from strings.ijs has this definition:

   deb =: #~ (+. (1: |. (> </\)))@(' '&~:)

NB. Here is a slightly faster deb:

   fdeb =: [ #~ [: -. [: (] *. 1&|.) ' ' = [
  
NB. s is the test string; w is its boxed words

   w=.;:s=.'now is the time for all good men to come to the aid of their 
country'
   w
+---+--+---+----+---+---+----+---+--+----+--+---+---+--+-----+-------+
|now|is|the|time|for|all|good|men|to|come|to|the|aid|of|their|country|
+---+--+---+----+---+---+----+---+--+----+--+---+---+--+-----+-------+

NB. show 
   1000 tx 'deb ,>w'
3.446e_6 3072

   1000 tx 'fdeb ,>w'
3.293e_6 3072

NB. same value for both the old and new fun
   (deb -: fdeb),>w
1

NB. the results match the original string
   s -: fdeb ,>w
1

However, it's not exactly the same as deb: it doesn't remove a single leading 
blank, as does deb (which, IMHO, is not necessarily an "extra" blank anyway).

Alan



----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to