From the C# documentation it states that the @ symbol is an Identifier. 2.4.2 Identifiers The prefix “@” enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a […]
Category: C#
Was detecting a file stream if it was Unicode encoded or not, so though I would share the code. Let say you an xml file that you need to detect if it has the Unicode BOM in the file. If you wish to know more about BOM look it up at wikipedia
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
//open the helloworld.xml file Stream fs = new FileStream("helloworld.xml", FileMode.Open); byte[] bits = new byte[3]; fs.Read(bits, 0, 3); // UTF8 BOM is like 0xEF,0xBB,0xBF if (bits[0] == 0xEF && bits[1] == 0xBB && bits[2] == 0xBF) { //utf8 do something } //UTF16 BOM is like 0xFF, 0xFE if (bits[0] == 0xFF && bits[1] == 0xFE) { //utf16 do something } |
Hope that […]