Skip to content

trim, ltrim, rtrim

Remove leading or trailing nulls from a list

 trim x     trim[x]
ltrim x    ltrim[x]
rtrim x    rtrim[x]

Where x is a vector or non-null atom, returns x without leading (ltrim) or trailing (rtrim) nulls or without either (trim).

q)trim "   IBM   "
"IBM"
q)trim 0N 0N 1 2 3 0N 0N  4 5 0N 0N
1 2 3 0N 0N 4 5

q)ltrim"   IBM   "
"IBM   "

q)rtrim"   IBM   "
"   IBM"

q)trim"a"
"a"
q)trim 42
42

Implicit iteration

trim, ltrim, and rtrim are string-atomic and apply to dictionaries and tables.

q)trim(("fox";("jumps ";"over   "));("a";"dog "))
"fox" ("jumps";"over")
"a"   "dog"

q)ltrim`a`b!(("fox";("jumps ";"over   "));("a";"dog "))
a| "fox" ("jumps ";"over   ")
b| "a"   "dog "

q)rtrim ([]a:("fox";("jumps ";"over   "));b:("a";"dog "))
a                b
----------------------
"fox"            "a"
("jumps";"over") "dog"

Domain and range

domain: b g x h i j e f c s p m d z n u v t
range:  b g x h i j e f c s p m d z n u v t

Drop
Strings