# Get string array from datatable column

**URL:** <https://forum.uipath.com/t/get-string-array-from-datatable-column/349403>\
**Category:** Studio\
**Tags:** string-array, datatable, system\
**Created:** [September 29, 2021, 2:09pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403 "2021-09-29T14:09:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![FJJJ](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/fjjj/32/180523_2.png) [@FJJJ](https://forum.uipath.com/u/FJJJ)\
**Post date:** [September 29, 2021, 2:09pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/1 "2021-09-29T14:09:33Z")

</div>

Hey,  
I have a datatable with string entries and I want to retrieve a string array from a certain column. I tried

**yourdatatablename.AsEnumerable().Select(Function (a) a.Field(of string)(“yourcolumnname”).ToString).ToArray()**

but it throws an error saying “‘Field’ is not a member of ‘Char’”. Can anyone help?

Best,  
Fredi

---

<div class="post-metadata">

**Author:** ![lakshman](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lakshman/32/523490_2.png) [@lakshman](https://forum.uipath.com/u/lakshman)\
**Post date:** [September 29, 2021, 3:02pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/2 "2021-09-29T15:02:40Z")

</div>

@FJJJ

Welcome to our UiPath community.

Try below expression.

```
         yourdatatablename.AsEnumerable().Select(Function (a) a.Field(of string)(“yourcolumnname”)).ToArray()

```

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [September 30, 2021, 1:30am UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/3 "2021-09-30T01:30:06Z")

</div>

Hi,

Probably, type of your **yourdatatablename** is String. Can you try to modify its type to DataTable?

Regards,

---

<div class="post-metadata">

**Author:** ![Palaniyappan](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/palaniyappan/32/524095_2.png) [@Palaniyappan](https://forum.uipath.com/u/Palaniyappan)\
**Post date:** [September 30, 2021, 3:12am UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/4 "2021-09-30T03:12:12Z")

</div>

> [@FJJJ](#):
>
> yourdatatablename.AsEnumerable().Select(Function (a) a.Field(of string)(“yourcolumnname”).ToString).ToArray()

Hi  
**Your expression is absolutely right**

That’s how we get the column value as a array

**But I feel the error is with the variable Yourdatatablename  
Check whether it is a datatable or some other variable type  
Change the type of that variable and give a try**

Cheers @FJJJ

---

<div class="post-metadata">

**Author:** ![FJJJ](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/fjjj/32/180523_2.png) [@FJJJ](https://forum.uipath.com/u/FJJJ)\
**Post date:** [September 30, 2021, 6:44am UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/5 "2021-09-30T06:44:09Z")

</div>

Hi  
and thank you all for the quick responses! It was indeed a wrong datatype for the datatable, my bad 😓  
However this is just one step of what I want to get: I want to extract something like a dictionary that consists of keys each one representing the occurence of a certain element in the column and the corresponding value being an int32 array, that contains all the indices of the rows, in which the key value appears in the column.  
Example for column4:  
 ![Capture](https://global.discourse-cdn.com/uipath/original/3X/9/2/92bdc50f11096823a5d7640c756937dd39b310ee.png)

…should result in a dictionary of:  
{{“element1”, {0,1,5}},  
{“element2”, {2,6,8}},  
{“element3”, {3,4,7}}}

Is there a better and quicker way than iterating through all the rows in a for loop for getting the int32 arrays?

Best,  
Fredi

---

<div class="post-metadata">

**Author:** ![Charbel1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/charbel1/32/247994_2.png) [@Charbel1](https://forum.uipath.com/u/Charbel1)\
**Post date:** [September 30, 2021, 12:19pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/6 "2021-09-30T12:19:15Z")

</div>

Why do you want to avoid a for each loop? Do you have a big excel file?

---

<div class="post-metadata">

**Author:** ![FJJJ](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/fjjj/32/180523_2.png) [@FJJJ](https://forum.uipath.com/u/FJJJ)\
**Post date:** [September 30, 2021, 12:32pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/7 "2021-09-30T12:32:06Z")

</div>

yes, it has about 20000 rows and I already tried and it took about 30min

---

<div class="post-metadata">

**Author:** ![Charbel1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/charbel1/32/247994_2.png) [@Charbel1](https://forum.uipath.com/u/Charbel1)\
**Post date:** [September 30, 2021, 12:33pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/8 "2021-09-30T12:33:44Z")

</div>

Okay, I’m working on it.

---

<div class="post-metadata">

**Author:** ![Charbel1](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/charbel1/32/247994_2.png) [@Charbel1](https://forum.uipath.com/u/Charbel1)\
**Post date:** [September 30, 2021, 1:03pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/9 "2021-09-30T13:03:20Z")

</div>

Here is the workflow:

[Forum\_LINQElementsIndex.xaml](https://forum.uipath.com/uploads/short-url/32k1cRBAXRxhXcaA5zT0A6NQeZ3.xaml) (7.2 KB)

Let me know if it works well with you and how much time it will take.

Best,  
Charbel

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [September 30, 2021, 2:10pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/10 "2021-09-30T14:10:37Z")

</div>

Hi,

FYI, another solution using Invoke Code:

![img20210930-5](https://global.discourse-cdn.com/uipath/original/3X/f/2/f2095164d2e3904d25ab5e35285490712d24cf31.png)

```
dt = dt.AsEnumerable.Select(Function(r,i) 
    If (Not dict.ContainsKey(r("col4").ToString)) Then
    dict.Add(r("col4").ToString,New List(Of Int32))
    End If
        dict(r("col4").ToString).Add(i)
    Return r
End Function
).CopyToDataTable

```

[Sequence2.xaml](https://forum.uipath.com/uploads/short-url/ugpulyZtWIIA611GKoAcLnfugFg.xaml) (10.1 KB)

Regards,

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [October 6, 2021, 12:09pm UTC](https://forum.uipath.com/t/get-string-array-from-datatable-column/349403/11 "2021-10-06T12:09:10Z")

</div>

Closed on October 6, 2021, 12:09pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
