# Split a column of strings and enumerate them

**URL:** <https://forum.kx.com/t/split-a-column-of-strings-and-enumerate-them/10037>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [June 29, 2015, 5:09pm UTC](https://forum.kx.com/t/split-a-column-of-strings-and-enumerate-them/10037 "2015-06-29T17:09:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hoffmanroni1](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hoffmanroni1](https://forum.kx.com/u/hoffmanroni1)\
**Post date:** [June 29, 2015, 5:09pm UTC](https://forum.kx.com/t/split-a-column-of-strings-and-enumerate-them/10037/1 "2015-06-29T17:09:00Z")

</div>

I have a table that has a column of type string with a max width of 4. &nbsp;I want to split that string up into four separate columns representing each character and then enumerate them so that queries against the table are faster. &nbsp;So for example,

t:(str:())

&nbsp; &nbsp; &nbsp; &nbsp; str

* * *

0 &nbsp;| "T &nbsp; &nbsp;"

1 &nbsp;| " &nbsp;FT"

2 &nbsp;| " &nbsp; &nbsp;C"

and I want

&nbsp; &nbsp; &nbsp; &nbsp;str &nbsp; &nbsp; &nbsp;| col1 | col2 | col3|

* * *

0 &nbsp;| &nbsp;&nbsp;"T &nbsp; &nbsp;" | T &nbsp; | &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; |

1 &nbsp;| &nbsp;&nbsp;" FT " | &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp;F | &nbsp; T &nbsp;|

2 &nbsp;| &nbsp;&nbsp;" &nbsp; &nbsp;C" | &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp;C |

When I do something like

select col1: str[0], col2:str[1], col3:str[2] from t

output looks like&nbsp;

&nbsp; &nbsp; col1 | col2 | col3

* * *

0 | T &nbsp; | &nbsp;F | &nbsp;

1 | &nbsp; &nbsp; &nbsp;| &nbsp;T |

2 |

3 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; C

---

<div class="post-metadata">

**Author:** ![Tom\_Martin11](https://avatars.discourse-cdn.com/v4/letter/t/9de0a6/32.png) [@Tom\_Martin11](https://forum.kx.com/u/Tom_Martin11)\
**Post date:** [June 29, 2015, 5:18pm UTC](https://forum.kx.com/t/split-a-column-of-strings-and-enumerate-them/10037/2 "2015-06-29T17:18:00Z")

</div>

q)t:(str:(“T “;” FT”;" C"))

q)update col1: str[;0], col2:str[;1], col3:str[;2], col4:str[;3] from t

str col1 col2 col3 col4

--------------------------

"T " T

" FT" F T

" C" C

---

<div class="post-metadata">

**Author:** ![hoffmanroni1](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hoffmanroni1](https://forum.kx.com/u/hoffmanroni1)\
**Post date:** [June 29, 2015, 5:22pm UTC](https://forum.kx.com/t/split-a-column-of-strings-and-enumerate-them/10037/3 "2015-06-29T17:22:00Z")

</div>

Works, thanks Tom

---

<div class="post-metadata">

**Author:** ![hoffmanroni1](https://avatars.discourse-cdn.com/v4/letter/h/8dc957/32.png) [@hoffmanroni1](https://forum.kx.com/u/hoffmanroni1)\
**Post date:** [June 29, 2015, 6:08pm UTC](https://forum.kx.com/t/split-a-column-of-strings-and-enumerate-them/10037/4 "2015-06-29T18:08:00Z")

</div>

Actually I am having trouble casting this to a symbol. &nbsp;And I would like to enumerate these columns. &nbsp;

First of all, if I do&nbsp;

update col1: `$str[;0], col2:`$str[;1], col3:`$str[;2], col4:`$str[;3] from t

it ends up the entire columns for each row, can I just cast that column to a symbol?

I need to cast to a symbol because I want to enumerate it, I can’t quite figure out how to enumerate a column, I know that .Q.en enumerates the sym column but if I want to have another enum from these four columns combined how would I do that?
