Remove all spaces from a datatable

Hello,

I need to remove all spaces from a datatable. There is a simple way without iterate each row and column?

Thak you

1 Like

Hi,

What do you mean exactly? Do you want to remove rows that have nothing in a field, or do you want to trim all the spaces for every field?

If you are looking to perform a trim on all the values in the table to remove their spaces, you will most likely need to run it through a For each, because you can’t manipulate a datatable using other methods. You can however convert it to text, then use string manipulation which would be fast with no for each, but it does make it more complex.

The alternative to this is to use Excel features. For example, if you have Excel open you can perform a Select All, Ctrl+h for Find and Replace, then input " " and replace with nothing, then choose Replace All.

Those are my thoughts. I hope it helps.
Regards.

C

HI,

I have a scenario like this (this is an exemplificative example, so don’t worry about error):

I need to get a data table from a screaping into an application that work in a citrix enviroment. The table can be have some hidden rows, so to get all I need to send a hotkey to go down and repite the screaping. When I arrive to the end of table could happen that I get duplicate rows, because them remain visible from previous iteration.
I used dt=dt.DefaultView.ToTable(True) to delete it but,since the citrix screaping is unstable, the duplicate rows come with some spaces of difference and the robot can’t recognize it.

1 Like

Hi @Siltra,
Try this code
(From p in dt.Select() where( From q in dt.Select() where string.Join(",",q.ItemArray).Replace(" ","").Equals(string.Join(",",p.ItemArray).Replace(" ","")) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

i hope this one work for you.

Regards,
Arivu

HI @arivu96,

I try this code on final table but it seems to return only the last screaping, losting all previous values.