UTF-8 without BOM

前端 未结 10 1781
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 15:31

I have javascript files that I need them to be saved in UTF-8 (without BOM), every time I convert them to the correct format in Notepad++, they are reverted back to

相关标签:
10条回答
  • 2020-11-22 15:34

    UTF-8 - "Save As" (Without Signature) Default - Request to include Default for UTF Without Signature

    VS 2017 natively supports EditorConfig so a recommended solution is to add .editorconfig file to your code base and set charset => utf-8. Then once you save a file it will be saved as UTF-8 without BOM.

    0 讨论(0)
  • 2020-11-22 15:34

    For Visual Studio Code do the following:

    1. From bottom right, select current encoding
    2. From options, Select Save with enconding
    3. From options, select UTF-8
    0 讨论(0)
  • 2020-11-22 15:44
    UTF8Encoding utf8EmitBOM = new UTF8Encoding(false);
    StreamWriter  sw = new StreamWriter(Path.Combine(sourcefilePath, fileName), false, utf8EmitBOM);
    

    This code will create file in UTF-8 without BOM

    0 讨论(0)
  • 2020-11-22 15:47

    Even with Dave81's solution, Visual Studio 2015 Community was still reverting my file to UTF8-BOM every single time I save that html file.

    When I created that html file, I right-clicked on the project and selected "Add" then added an HTML file.

    By default, Visual studio will include a <meta charset="utf-8" /> tag in your HTML file.

    Simply removing the tag then applying Dave81's solution made the problem go away for real this time.

    It seems the Visual Studio parse your html file and when it sees that tag it converts the file to UTF8-BOM without any consideration to the original file format (UTF-8 without BOM).

    I would have made a comment directly under Dave81's solution, but I didn't have enough points to do so...

    0 讨论(0)
  • 2020-11-22 15:48

    For vs2010 c++, there will be problems with UTF8 without BOM, when source files contain multi-byte characters(eg. Chinese).

    Those characters will not be recognized correctly without BOM, and result in failed compling.

    0 讨论(0)
  • 2020-11-22 15:49

    Now with pictures.

    1. Go to File -> Save As.

    2. Then on Save button click on triangle and click Save with Encoding....

    3. Click ok to overwrite the file then from list of encodings find UTF-8 Without signature -> Click OK.

    Hope this saves you some time.

    0 讨论(0)
提交回复
热议问题