In my project; I need to query our database, and then use the result set to generate a fixed width flat file. I'm using a solution based off of this question. All is well and good for 99% of the records, but I am running into one situation that's causing issues:
In the event of "special characters", like ® or ™; it ends up skewing the length of the column when writing to a text file. When I check the results, I get ® in the event of the ® symbol, and â„¢ in the event of ™.
I'd like to keep the garbled characters in the final result (for now), cause it'll get picked up later in the validation/sanitation process. (i.e. in the case of a size like '5½'; I don't want to simply drop the ½ cause then it'll look like '5')
Is there a way to get the actual length of what those special characters will get serialized to so I can take that into account?
EDIT Here's the code that does the text writing:
using (var fileStream = new StreamWriter(fileName, false))
{
foreach (
var fileRecord in recordTypes.Select(record => record.RetrieveForImport(startDate, endDate)).SelectMany(records => records))
{
try
{
fileStream.WriteLine(fileRecord.Serialize());
}
catch (MySerializationException ex)
{
LogSerializationError(fileRecord, ex.Message);
}
}
}
And I'm using TextPad to verify the results afterwards.