
One API reads UTF-8 with a BOM and the other API reads without a BOM. Each CSV file encoding type will be consumed by different non-standardized APIs.


Last week, at my job, I needed to develop one functionality that outputs CSV files with a BOM and other CSV files with pure UTF-8 (without a BOM). The only thing that is necessary to be considered is about a difference between pure UTF-8 and UTF-8 with a BOM. I saw some answers at this post and it's possible to be considered completed base knowledge, because I have a several approaches in C# Programming to resolve the same problem. String s4 = HttpServerUtility.UrlTokenEncode(bytes) // gsjqFw2īyte decBytes4 = HttpServerUtility.UrlTokenDecode(s4) String s3 = Convert.ToBase64String(bytes) // gsjqFw=īyte decByte3 = Convert.FromBase64String(s3) String s2 = BitConverter.ToString(bytes) // 82-C8-EA-17īyte decBytes2 = new byte ĭecBytes2 = Convert.ToByte(tempAry, 16) Using UTF-8 or other Encoding object will get similar results The output string is already URL friendly! The downside is it needs System.Web assembly if your project is not a web project.Ī full example: byte bytes = // A byte array contains non-ASCII (or non-readable) characters You can easily convert the output string back to byte array by using HttpServerUtility.UrlTokenDecode. If you want to use the string in a URL, you need to explicitly encode it.

Note: The output string could contain '+', '/' and '='. NET built-in method to convert the string back to byte array.Ĭonvert.ToBase64String You can easily convert the output string back to byte array by using Convert.FromBase64String. There're at least four different ways doing this conversion.Įncoding's GetString, but you won't be able to get the original bytes back if those bytes have non-ASCII characters.īitConverter.ToString The output is a "-" delimited string, but there's no.
