bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-apl] Not a bug, need help coding search&replace on a vector


From: Fred Weigel
Subject: [Bug-apl] Not a bug, need help coding search&replace on a vector
Date: Tue, 21 Jun 2016 14:49:57 -0400

Christian Robert

For this, try the "toronto toolkit" in our bits&pieces.

There is a function "condense"

' ' condense '  a b   c d  '

a b c d

Which is what you want (I think). Uses ∆db (delete blanks). Preferable
to get from the toolkit -- functions reproduced below.

∇y←d condense v;b
 ⍝remove redundant blanks and blanks around characters specified in <d>
 ⍝.d 1985.6.20.10.10.10
 ⍝.e 'apple,betty,cat,,dog' = ',' condense '  apple, betty, cat, , dog'
 ⍝.k delete-characters
 ⍝.t 1992.3.10.20.19.23
 ⍝.v 1.1
 ⍝v is character vector (rank 1) only
 ⍝remove leading, trailing, and multiple internal blanks
 y←∆db,v
 ⍝remove blanks around characters specified in <d>
 ⍝e.g. if <d> =<,>, blanks are removed around commas in 'a , b , d'
 b←y∈d
 y←(∼(y=' ')∧(1⌽b)∨¯1⌽b)/y
∇

∇y←∆db v;b
 ⍝delete blanks (leading, trailing and multiple) from v (rank 0 - 2)
 ⍝.e 'apple betty cat' = ∆db '  apple  betty  cat  '
 ⍝.k delete-characters
 ⍝.v 1.1
 →((0 1 2=⍴⍴v),1)/l1,l1,l2,err1
 l1:
 b←' '≠v←' ',v
 y←1↓(b∨1⌽b)/v
 →0
 l2:
 b←∨⌿' '≠v←' ',v
 y←0 1↓(b∨1⌽b)/v
 →0
 err1:⎕←'∆db rank error'
∇






reply via email to

[Prev in Thread] Current Thread [Next in Thread]