Remove non ascii characters prior to creating a csv file

I’m running into a challenge when outputting a delimited file created from an Excel report.
The report has hidden characters that don’t appear when I write a csv file. When I use “us-ascii” as the encoding value, in my “write csv file”, I can see some data with “?”. Is there a way to remove all non ascii fields from my entire table. I’ve seen regex examples for strings but was curious about tables. I’m already trimming the data using the trim function. Can I add to it?

DtExcel.AsEnumerable.Select(Function(x) dtModified.LoadDataRow(New Object() {x(“column0”).ToString.Trim


Can you try the following expression? This will remove non-ascii character in whole the datatable.

DtExcel.AsEnumerable.Select(Function(r) DtExcel.Clone.LoadDataRow(r.ItemArray.Select(Function(s) System.Text.RegularExpressions.Regex.Replace(s.ToString(),"\P{IsBasicLatin}","").Trim()).ToArray() ,False)).CopyToDataTable()

If you want to convert it at specific column, please add the above regex to your expression.


Thank you Yoichi!

This removed the non-ascii characters.

1 Like

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