Inconsistency in reading a flat file ("?") C #

0

I am reading a flat UTF-8 source code file and I read it with UTF-8, so far everything works fine, but I have a record that for reasons I can not find yet, it brings me a question mark when I register it in the BD, but I do all the follow-up and I can not find the reason.

Source file (They do not have space at the end, but when I try to erase the letter E in the flat file, I must give the button to delete twice twice, I think it is related to this)

Reading the file in c #

In the model before registering.

And when I register. The famous question mark

Thank you very much for your help!

    
asked by Dahiana 03.09.2018 в 18:08
source

1 answer

1

It seems obvious that you have some kind of hidden or control character in your text data file, which causes the famous ? to appear when storing it in the database.

One way to "clean it up" is to use the following code, after the Split you do in the tabs:

string[] rowData = row.Split('\t');
for (int i=0;i< rowData.Length;i++)
{
     rowData[i] = new string(rowData[i].Where(c => char.IsLetter(c) || char.IsDigit(c)).ToArray());
}

This is just one of the options. You could use regular expressions, or filter by !char.IsControl(c) .

    
answered by 03.09.2018 в 18:19