1

Is there a setting in Visual Studio Code that helps showing non-ASCII characters in the editor?

I met compilation errors with such non-ASCII characters hidden in C++ code:

error: stray '\302' in program

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
leiyc
  • 903
  • 11
  • 23
  • 1
    See https://stackoverflow.com/a/70164173/836330 for highlighting non-standard ascii characters in vscode. – Mark Nov 30 '21 at 04:31
  • The next two (or one) after "\302" (an octal number) are ***also part of the error message***. For the very common ones [NO-BREAK SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?utf8=0x) (Unicode code point U+00A0) and [ZERO WIDTH SPACE](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128) (Unicode code point U+200B), it is 240 and 200 + 213, respectively. – Peter Mortensen Apr 25 '23 at 16:39
  • The canonical question for "error: stray in program" is *[Compilation error: stray ‘\302’ in program, etc](https://stackoverflow.com/questions/19198332/)* (though it is currently missing comprehensive answers). – Peter Mortensen Apr 25 '23 at 16:45
  • The most common ones can be searched for (and replaced) using the regular expression `\x{00A0}|\x{200B}|\x{200C}|\x{FEFF}|\x{2013}|\x{2014}|\x{201C}|\x{201D}|\x{2212}|\x{00E4}|\x{FFFC}|\x{FFFD}|\x{2217}|\x{200C}|\x{202B}|\x{202A}|\x{FF1A}|\x{21B5}` (NO-BREAK SPACE, ZERO WIDTH SPACE, ZERO WIDTH NON-JOINER, ZERO WIDTH NO-BREAK SPACE, EN DASH, EM DASH, LEFT DOUBLE QUOTATION MARK, RIGHT DOUBLE QUOTATION MARK, MINUS SIGN, LATIN SMALL LETTER A WITH DIAERESIS, OBJECT REPLACEMENT CHARACTER, REPLACEMENT CHARACTER, ASTERISK OPERATOR, POP DIRECTIONAL FORMATTING, RIGHT-TO-LEFT EMBEDDING, etc.). – Peter Mortensen Apr 25 '23 at 22:13

1 Answers1

2

Try the Gremlins extension.

It reveals some characters that can be harmful, because they are invisible or looking like legitimate ones. It was inspired by Sublime Gremlins.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mohammad
  • 21
  • 3
  • Can you add a reference to it? (But *** *** *** *** *** *** *** *** *** ***without*** *** *** *** *** *** *** *** *** *** "Edit:", "Update:", or similar - the answer should appear as if it was written today.) – Peter Mortensen Apr 25 '23 at 16:47
  • [Possible reference](https://stackoverflow.com/questions/64093078/how-can-i-find-unicode-characters-that-are-not-utf-8-in-visual-studio-code/65405031#65405031). – Peter Mortensen Apr 25 '23 at 17:14