Search code examples
kdb

remove \n after replace " " in kdb+


I have a table named "t", with the column, "x". It looks as follows:

     `INPUT:"\n This is sample code"
     RESULT: "This is sample code"`

I want to remove \n in particular table column values


Solution

  • Here is an example of how to use ssr to achieve the desired trimming you require in a table setting:

    q)t:([]a:1 2 3;b:("\nThis is sample code";"More good sample code";"\n More sample code"))
    q)t
    a b
    -------------------------
    1 "\nThis is sample code"
    2 "More good sample code"
    3 "\n More sample code"
    q)@[t;`b;{trim ssr[x;"\n";""]}@']
    a b
    -------------------------
    1 "This is sample code"
    2 "More good sample code"
    3 "More sample code"
    

    Hope this helps.