how can I append a string to a vector of strings? - Kdb+ / qStudio

Home Forums Kdb+ / qStudio how can I append a string to a vector of strings?

This topic contains 1 reply, has 2 voices, and was last updated by  Ryan Hamilton 4 years, 7 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #111069

    Michael

    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.

    #111071

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.