MichaelGuest
Hi,
How can I append a string to a vector of strings?
I keep getting a strange result, where the hard defined ones are ok but the last string goes odd.
Kdb considers strings as a sequence of characters. Therefore sometimes it’s a little odd how you have to interact with them.
For strings in a list we can do this:
`q)st:(“aa”;”bb”)
q)st,”cc” / this is wrong as kdb attempts to append as a lsit of characters
“aa”
“bb”
“c”
“c”
q)st,enlist “cc” / we must enlist the string
“aa”
“bb”
“cc”`
For prefix/postfix of strings in a table we can use the each-right / each-left adverbs:
`q)t:([] v:(“aa”;”bb”))
q)t
v
—-
“aa”
“bb”`
q)update (“pre-“,/:v) from t
v
——–
“pre-aa”
“pre-bb”
q)update (v,\:”-post”) from t
v x
————–
“aa” “aa-post”
“bb” “bb-post”
Notice that the parentheses are needed to prevent kdb getting confused by the comma.