Removing BOM from string
-
Hi, I have developed a rountine that builds a string using the StringBuilder class and then creates a CSV file from the string. The CSV file is then used to import data into another application. However, after creating the CSV file there is BOM at the start of the file which is preventing me from importing into the 3rd party application. My question is how can I create the CSV file without the BOM? Thanks for your time.
-
Hi, I have developed a rountine that builds a string using the StringBuilder class and then creates a CSV file from the string. The CSV file is then used to import data into another application. However, after creating the CSV file there is BOM at the start of the file which is preventing me from importing into the 3rd party application. My question is how can I create the CSV file without the BOM? Thanks for your time.
-
Hi, I have developed a rountine that builds a string using the StringBuilder class and then creates a CSV file from the string. The CSV file is then used to import data into another application. However, after creating the CSV file there is BOM at the start of the file which is preventing me from importing into the 3rd party application. My question is how can I create the CSV file without the BOM? Thanks for your time.
-
Thanks both of you but I have resolved it. I was using:
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)
which was creating the file as UFT-8 which seemd to insert the BOM. I have changed it to:
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False, System.Text.Encoding.ASCII)
which doesn't insert the BOM. Thanks for your time.
-
Thanks both of you but I have resolved it. I was using:
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False)
which was creating the file as UFT-8 which seemd to insert the BOM. I have changed it to:
Dim outFile As IO.StreamWriter = My.Computer.FileSystem.OpenTextFileWriter(csvFile, False, System.Text.Encoding.ASCII)
which doesn't insert the BOM. Thanks for your time.
As you discovered there is a difference between UTF-8 and ASCII. UTF-8 files always have the header 0xEF 0xBB 0xBF so any program reading text files should check for this and not just assume the content is pure ASCII. C# programs tend to handle this automatically in most cases.
MVP 2010 - are they mad?
-
As you discovered there is a difference between UTF-8 and ASCII. UTF-8 files always have the header 0xEF 0xBB 0xBF so any program reading text files should check for this and not just assume the content is pure ASCII. C# programs tend to handle this automatically in most cases.
MVP 2010 - are they mad?
Another lesson learned :D Thanks
-
Another lesson learned :D Thanks