1

I used to be able to convince the Visual Studio editor to save my source files in plain old 8 bit ascii, no BOM. I think all I had to do was set project->properties->configuration properties->Character Set to "Not Set". That was then. Now it's Visual Studio 2017, and I cannot figure out a way to do it.

QUESTION: How?

I have tried setting that properties value to "inherit from parent ...". I also tried typing in "ascii". It accepts that value, but it has no effect.

EDIT - I figured it out. See the answer I posted.

Jive Dadson
  • 16,680
  • 9
  • 52
  • 65
  • Since when did "project->properties->configuration properties->Character Set" set the encoding of the current file in the editor? – Dai Apr 06 '18 at 01:30
  • @Dai - I don't know. Do you think there was a time when it did not? All that matters to me is what it does now. – Jive Dadson Apr 06 '18 at 01:50
  • I don't see "Configuration properties" anywhere in my Visual Studio installation. If you're referring to the "Character set" property in C++ projects then that refers to the runtime library's handling of text, not how files are saved in the editor. – Dai Apr 06 '18 at 02:13
  • @Dai - Now I am confused again, and I thank you for that. Somehow back in the day, I got VS to save files in us-ascii, and I don't know how I did it. See the revision of the question. I'm giving you a well-earned +1, but still longing for the old days. – Jive Dadson Apr 06 '18 at 02:35
  • See https://stackoverflow.com/questions/49623731/what-is-the-default-encoding-for-source-files-in-visual-studio-2017 – Sergey Vlasov Apr 06 '18 at 02:44
  • Out of curiosity, why do you want to save in ASCII and not UTF-8 (with or without the BOM)? – Dai Apr 06 '18 at 03:19
  • @Dai - No good reason probably. I do not know much about this subject. Is it the case that utf-8 (no bom) is identical to ascii if the file only contains ascii characters? – Jive Dadson Apr 06 '18 at 03:39
  • Correct, UTF-8 is binary-compatible with ASCII (7-bit characters). – Dai Apr 06 '18 at 03:58
  • @Dia - Thanks. I winkled the solution out of the web. Your questions helped. – Jive Dadson Apr 06 '18 at 04:02

2 Answers2

3

File > Save As > Save with Encoding.

enter image description here

Dai
  • 141,631
  • 28
  • 261
  • 374
1

Okay, this does what I want. (If the file contains only ASCII chars (7 bit), then utf-8 (not utf-8-bom) is identical to ASCII. I am sure I knew that at one time, but old folks forget things.)

Here's what to do...

Download an extension: Editor Config Language Service... Close Visual Studio and install the extension.

Re-start VS, and open the solution. Open Solution Explorer. Right click on the solution, and click Add. At the bottom of the list, click editorconfig file.

Click on Solution Items/editorconfig to edit it.

In the section [*], add the following

charset = utf-8

Initially, mine looked like this:

[*]
end_of_line = crlf
charset = utf-8

[*.xml]
indent_style = space
Jive Dadson
  • 16,680
  • 9
  • 52
  • 65