How to trim whitespaces from column names in datatable


#1

I have a datatable which has leading and trailing whitespaces. I want to remove them but not the ones in the middle.
For eg: " Column 1 " to “Column 1”


#2

@jamnanin

try this
ListA=(From p in dt.columns.CastOf(System.Data.DataColumns)
Select Convert.ToString( p ).Trim).ToList

You will get the column names without spaces.

Regards,
Mahesh