How to append a string to all column headers in dt

Dear all,
I need help in adding a string to all column headers in a datable
Location, City,Country

i need to append “Select.” to all the headers
output should look like
Select.Location, Select.City, Select.Country

please help

Use a for each loop:

For each item in DT.Columns
str = str+";"+“Select.”+item.ColumnName

Now use a Generate DT with str as ColumnNames, pass it in Input and Column Separator as “;”

This will Generate a DT with required columns.

Check this below workflow, @ashwini.bagewadi
Uipath_AddStringToHeaders.xaml (5.8 KB) and I have used below query to do that - String.Join(",",InputDt.Columns.Cast(Of System.Data.DataColumn).Select(Function(x) “Select.”+x.ColumnName.ToString).ToArray())
Hope this may help you :slight_smile:

1 Like

Thank you so much for answering to my question. I tried to execute as your advice, but have a doubt, what is .ColumnName at the end of str assign? is it the header column name like “Location”? I have a datatable with header names :Location, City,Country along with its contents, and want to create a new datatable with changed headers along with its contents. It will be really helpful if you solve this doubt

@ashwini.bagewadi Yes. .ColumnName at the endof str assign gives the value “location”. It fetches all headers in a for each loop and appends them to the str and later uses the separator to split the string and use new headers as Select.ColumnName

Thank you so much @Manish540 for your answer, that did give me an output, but it is giving me headers in string format, and i need the headers in datatable format

Compiler error(s) encountered processing expression “str+”;"+“Select.”+item.ColumnName".
Option Strict On disallows late binding.
I getting the above error for the assign.

If you just need to rename the headers (the column names), you can do so in the For Each Loop:

col.ColumnName = "Select." + col.ColumnName





This is great :smiley:. It totally worked. Thank you soo much @ptrobot

1 Like

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