« How do I convert from symbol to integer? | Main | How do I parse a ctrl-A delimited string? »

How do I cast a string to a symbol?

By applying the $ (cast) operator while passing ` (the null symbol) as its left argument:

q)` $ "foo"

The cast operator also accepts an uppercase type character as its left argument:

q)"S" $ "foo"

Moreover, you can convert a list of strings at once:

q)"S" $ ("foo"; "bar"; "baz")

To go the other way, use the string function:

q)string `foo

Since the string function is implemented as the monadic form (i.e., single argument overload) of the k function $


— it is also possible to write the above cast as follows:


Although we don't recommend it, we thought you should know in case you see it in the wild.

See also: type

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
All HTML will be escaped. Textile formatting is allowed.