# The method to use Replace in a DataTable help

**URL:** <https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209>\
**Category:** Studio\
**Tags:** question, system, activities\
**Created:** [October 18, 2024, 6:10am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209 "2024-10-18T06:10:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![22222222asas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/22222222asas/32/417152_2.png) [@22222222asas](https://forum.uipath.com/u/22222222asas)\
**Post date:** [October 18, 2024, 6:10am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/1 "2024-10-18T06:10:14Z")

</div>

I would like to know how to remove parentheses and whitespace from all the values in a DataTable while keeping the structure (rows and columns) intact. If I use `System.Text.RegularExpressions.Regex.Replace(TestDT, "\s*\(.*?\)\s*", "")`, I would need to convert it to a string, which would disrupt the rows and columns. Could you please provide a solution?  
Thank you in advance for your response.

---

<div class="post-metadata">

**Author:** ![Shahazeer\_Ummer\_D](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shahazeer_ummer_d/32/537483_2.png) [@Shahazeer\_Ummer\_D](https://forum.uipath.com/u/Shahazeer_Ummer_D)\
**Post date:** [October 18, 2024, 7:00am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/2 "2024-10-18T07:00:44Z")

</div>

Hi @22222222asas,

Based on the regex you provided refer the xaml attached below for the solution.

[Test.xaml](https://forum.uipath.com/uploads/short-url/j64Vytc6WcesXvyMj2I81Cr0Amp.xaml) (8.4 KB)

The LINQ query iterates over each row in the DataTable and applies the `Replace` function to every item (cell) in the row, removing whitespaces and parentheses. It then adds the modified rows to a cloned DataTable, preserving the original structure but with the cleaned-up data.

Hope this helps , Thank you 😀

---

<div class="post-metadata">

**Author:** ![Shahazeer\_Ummer\_D](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/shahazeer_ummer_d/32/537483_2.png) [@Shahazeer\_Ummer\_D](https://forum.uipath.com/u/Shahazeer_Ummer_D)\
**Post date:** [October 18, 2024, 7:30am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/4 "2024-10-18T07:30:37Z")

</div>

dt\_test.AsEnumerable().Select(Function(row) dt\_clone.LoadDataRow(row.ItemArray.Select(Function(item) item.ToString().Replace(" “, “”).Replace(”(“, “”).Replace(”)", “”)).ToArray(), False)).CopyToDataTable()

You can try this out instead of using regex.

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [October 18, 2024, 7:35am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/5 "2024-10-18T07:35:19Z")

</div>

@22222222asas  
similar to

> [@LINQ query to update(replace)datatable in uipath](https://forum.uipath.com/t/linq-query-to-update-replace-datatable-in-uipath/174612/8):
>
> @Rachel7 this is maybe a too quick shot as it replace any space in any column to NA and returns a datatable. But you can give a try (From r In dtData.AsEnumerable Select ia = r.ItemArray.toList Select ic = ia.ConvertAll(Function (e) e.ToString.Trim.Replace(" ","NA")).toArray() Select dtCorrected.Rows.Add(ic)).CopyToDataTable() NEW VERSION, simplified - replace all cols with only String.Empty content: (From d In dtData.AsEnumerable Let ra =d.ItemArray.Select(Function (x) If(isNothing(x), Not…

we can handle like

```auto
(From d In dtData.AsEnumerable
Let ra =d.ItemArray.Select(Function (x) If(isNothing(x), Nothing, Regex.Replace(x.toString,"YourPattern",""))).toArray
Select r = dtCorrected.Rows.Add(ra)).CopyToDataTable()

```

Maybe you can share some sample data with us, we could also check for simplification like a custom trim

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [October 18, 2024, 7:47am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/7 "2024-10-18T07:47:00Z")

</div>

ensure that " is used for double quotes and not the inverted ones “” (e.g. coming from copy paste)

---

<div class="post-metadata">

**Author:** ![22222222asas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/22222222asas/32/417152_2.png) [@22222222asas](https://forum.uipath.com/u/22222222asas)\
**Post date:** [October 18, 2024, 7:57am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/8 "2024-10-18T07:57:27Z")

</div>

@Shahazeer_Ummer_D

Thank you for your response! I used the Assign activity twice, and it worked perfectly. Have a great weekend!

---

<div class="post-metadata">

**Author:** ![22222222asas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/22222222asas/32/417152_2.png) [@22222222asas](https://forum.uipath.com/u/22222222asas)\
**Post date:** [October 18, 2024, 7:58am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/9 "2024-10-18T07:58:10Z")

</div>

@ppr  
Thank you for your response!  
The code you provided was perfect. Thank you!

---

<div class="post-metadata">

**Author:** ![ppr](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/ppr/32/464097_2.png) [@ppr](https://forum.uipath.com/u/ppr)\
**Post date:** [October 18, 2024, 8:00am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/10 "2024-10-18T08:00:23Z")

</div>

> [@22222222asas](#):
>
> @ppr  
> Thank you for your response!  
> The code you provided was perfect

Perfect, so you can close the topic by marking the solving post  
[Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum](https://forum.uipath.com/t/forum-faq-how-to-mark-a-post-as-a-solution/338723)

---

<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 21, 2024, 8:01am UTC](https://forum.uipath.com/t/the-method-to-use-replace-in-a-datatable-help/774209/11 "2024-10-21T08:01:21Z")

</div>

Closed on October 21, 2024, 8:01am UTC

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