cancel
Showing results for 
Search instead for 
Did you mean: 

Symbol with Trailing spaces

vikas_agarwal
New Contributor
Hi,

Got stuck in some issues with symbol and trailing space.

string `$"MF      " = "MF"
so it means, while converting a string to symbol, trailing spaces are removed.

Even following yield same results, Trailing spaces are removed:
gg:([]tm:`$())
;`gg insert(`$"vv    ")

But now if i am using c.cs from Kx. 
qc.k("insert", tableName, xdata);

where one of the xdata array item contains trailing spaces then it is not trimmed. it is inserted with spaces. May be because of byte array. 

I am also attaching the backup file(zzz to zip) that can be imported as
`. set get `:symbolSpaceBackup 


Let me know if there is some solution of it. other than trimming each and every item in the array base on the type of a column.


Regards,
Vikas
2 REPLIES 2

sohagan
New Contributor
I replied to this earlier but I am not sure what was wrong with google groups this morning.

Anyway; .Q.s will help you. http://code.kx.com/wiki/DotQ/DotQDots.

q)gg:([]tm:`$())
q)`gg insert(`$.Q.s"vv    ")
q)gg
tm
----------
"vv    "
q)meta gg
c | t f a
--| -----
tm| s        //stays on symbol

If I were you though I would avoid symbols if this is going to happen frequently...this has affects on the value:
You will have to include the internal " ... 
q)select from gg where tm like "\"vv*"

Whereas standard symbol you don't:
q)gg2:([]tm:enlist`vv)
q)select from gg2 where tm like "vv*"
tm
--
vv

I also don't know the affects of this on your sym file, assuming you are enumerating. Char is there for a reason so I would stick with it. 

Maybe differing opinions but anyway.

Thanks,
Sean


Thanks Sean for your detailed reply. 

In your example value in the symbol is not trailing spaces but we are trying to preserve the end spaces by some wrapper.
so following 2 inserts are same:
`gg insert(`$"\"vv    \"")     /I believe this one is same as `gg insert(`$.Q.s"vv    ")
`gg insert(`$"$vv    $")     / This one adds $ as a wrapper for spaces.


As you rightly said that above will have affect on value because i have to remember what are starting and closing characters. 
The question i posted was having trailing spaces in a symbol without any escape sequence. The actual symbol value was having spaces in the end. I dont know if it is possible or not or i am not understanding correctly.


What i have done currently is my application is that when i insert, i just trim the value and keep it symbol because there will be lot if duplicate values. Just wanted to avoid trim for every column that is inserted as symbol.