c# - Add byte order mark to a string via StringBuilder -


how can add byte order mark stringbuilder? (i have pass string method save file, can't modify method).

i tried this:

var sb = new stringbuilder(); sb.append('\xef'); sb.append('\xbb'); sb.append('\xbf'); 

but when view hex editor, adds following sequence: c3 af c2 bb c2 bf

the string huge, without , forth converting byte array.

edit: clarification after questions in comments. have pass string method takes string , creates file of on azure blob storage. can't modify other method.

two options:

  1. don't include byte order mark in text @ all... instead use encoding automatically include it
  2. include as character in stringbuilder:

    sb.append('\ufeff'); // u+feff byte-order mark character 

personally i'd go first approach normally, "i can't modify method" suggests may not option in case.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -