Remove particular Data columns by using Wildcards

Hello Guys,
I’m trying to use Filter Data Table to remove some redundant columns which name should start with “Column-”, such as “Column-1”, “Column-3”,“Column-5” and so on.
Can I use wildcards in Filter Wizard to remove all column name starts with “Column-”? Or do I have to put the redundant column name one by one in Filter Wizard?
image

Hi @he.cao
u can try this way

Read the excel file and store in dt1

now use below assign activity to get only column name starting with Column-

data_array = (From dc In dt.Columns.Cast(Of DataColumn)
Where dc.ColumnName.StartsWith(“Column-”)
Select dc.ColumnName).ToArray()

Now use for each loop to loop through each element in data_array [ datatype of data_array is String ]

Iniside the loop use Remove Data Column Activity to remove the column from the datacolumn by specifying the name of column

Regards,
Nived N
Happy Automation

1 Like

Hi from what @NIVED_NAMBIAR said we can do this way also,

data_array = (From dc In dt.Columns.Cast(Of DataColumn)
Where not dc.ColumnName.StartsWith(“Column-”)
Select dc.ColumnName).ToArray()

And again assign,

dt = dt.defaultview.totable(false,data_array) it will return only columns present in the array

4 Likes

Thanks @NIVED_NAMBIAR .
I had DT1 in variable, but I don’t know how to set the assign activity as you mentioned. :sweat_smile:
image
Could you please attach a screenshot how I should express in the assign activity?

Hi @he.cao
image

in the to side of assign activity specify the variable of datatype String array [String ]


I had specified the date type as String Array, but compiler error still exists in the expression editor.
image

Hi @he.cao put a ‘(’ before From

It works now. Thank you so much :+1: @NIVED_NAMBIAR

1 Like

@prasath_S Your suggestion works as well, Thank you!

1 Like

Hi @he.cao
if you got the solution, please mark the appropriate solution so that we can close the topic

sure, I’ve marked solutions that instructed by you and Prasath. Thank you guys.

1 Like

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