I am extracting string from an byte array. The string is a sql script.
String sql = System.Text.Encoding.GetEncoding(1200).GetString(script);
The first character is coming out to be junk(square box in preview). Due to which the whole script is failing. Any idea why this is happening?
I don’t want to specifically remove the first character. More interested in knowing why and how can this be avoided.
The first character(s) are probably Byte Order Marks (BOM).
You can use a StreamReader to automatically detect any BOM and select the appropriate encoding: