I want to remove all leading and trailing spaces from ALL cells in a datatable.
I have an idea where I can probably use nested for-each loop, but I am not sure exactly how to do this. I first thought about something like:
for each column in dt_Example.Columns:
__for each row in column
____Assign: dt_Example.Rows(row, column).ToString = dt_Example.Rows(row, column).ToString.Trim
but this is kind of too much work, and I don’t even think this works. Some cells have integer values too, so I am not sure if I can just put ToString.
Is there any smart way to remove all spaces from front and back of data in ALL cells in a data table?
Hmmm: I am not sure what I am doing wrong. Can anyone help me, please?
Trial 1: (in_dt_WithSpaces is an argument of type DataTable from which I want to get rid of all leading and trailing spaces from all cells.)
Trial 2 (Pseudo code):
i (of Int32, default set to 0 from variable tab)
j (of Int32, default set to 0 from variable tab)
while ( i < in_dt_withSpaces.Rows.Count ){
…while ( j < in_dt_WithSpaces.Columns.Count ){
……Assign: in_dt_WithSpaces.Rows(i)(j) = in_dt_WithSpaces.Rows(i)(j).ToString.Trim
……Assign: j = j + 1
…}
…Assign: i = i + 1
}
I tried the above code, but it doesn’t work. I am at my wits end…