Weird issue when using the 'Add new Item' option to add a text file to my VS2008 project
I am trying to add a text file to my project. Not that it is important but I am using these text files to store SQL statements. My project reads the SQL statement then uses it to gather data.
I use the right-click context menu from the project explorer to 'Add a new item', then select text file from the menu, change the file name and click the 'Add' button.
A blank template is displayed and no matter what I type, and save, when I read the file I get 3 garbage characters at the beginning of the file. You cannot see them in the editor but if you view the file in a hex editor you can see them.
Before you ask, no, it is not my read routine that is creating the characters as I used an 开发者_JS百科external edit to view the file and they're there. I think Visual Studio is putting them there.
Here is what the text looks like in a HEX editor:
SELECT ...etc..
^^^ Which doesn't bode well for my SQL statement.
Any thoughts?
They're just a UTF-8 byte order mark. They're three bytes, but a single character.
Whether they're a problem for you will depend on how your project reads the file. IIRC, StreamReader
will read and strip it, so you should be okay.
When you save the file, you can go to "File / Advanced Save Options" and select an encoding of
Unicode (UTF-8 without signature)
to avoid the BOM. It would probably be best to just change your code to cope though.
精彩评论