Utsav
Utsav

Reputation: 5918

Remove empty string from a list of strings in kdb

I have a list of strings:

q)l:("abc";"";"def";"");

How can we remove empty strings from the list l?

Desired Output:

("abc";"def")

My failed attempts:

q)l except ""
q)l except\: ""
q)l except 1#""

Upvotes: 0

Views: 1095

Answers (1)

Eliot Robinson
Eliot Robinson

Reputation: 666

Using enlist on the empty string will work:

q)l except enlist""
"abc"
"def"

In many cases, 1# and enlist can be used interchangeably, as long as the list is not empty. Applying 1# on an empty list will return an enlisted null of the empty list type provided:

q)1#`long$()
,0N
q)1#`symbol$()
,`
q)1#""
," "

Upvotes: 4

Related Questions