Send
Close Add comments:
(status displays here)
Got it! This site uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.nbsp; Note: This appears on each machine/browser from which this site is accessed.
Tabs and spaces in code files
1. Tabs and spaces in code files
When writing code, tabs and spaces can create issues.
A tab character moves the character position to the next tab stop, which could be 3, 5, 8, or some other setting.
To see the Notepad++ tab settings, select "Settings", "Preferences", "Tab Settings". Note: It is best not to check "Replace by space" since that can cause issues with indentation of code (though some programmers like that option).
When you put tab characters within text in double quotes, it may look fine in the editor, but when expanded on the command line when the program is run, the spacing may not be as desired.
2. Character codes
The tab character is an ASCII code #9 character.
The space character is an ASCII code #32 character.
3. Non-breaking space
The non-breaking space character is code #160. When copy-pasting code from, say, the Internet, strange characters like this one can end up in your code file - with various results that may not be desired.
4. Recommended style rule
Recommended style rule so this does not happen:
1. Always use tab characters, never spaces, for indentation - to the left of code statements in a source program.
2. Always use space characters, never tabs, within text strings - text within double quotes.
3. Only use raw tabs at the beginning of a line. Avoid using raw tabs in the middle of a line. Many editors remove tabs at the end of a line but, if not removed, these can sometimes cause issues too.
5. Notepad++
Many editors provide a way to see tabs and spaces.
In Notepad++, do the following.
Select "View", "Show Symbol", "Show White Space and TAB".
You will now be able to see where tab characters are within your code. To turn it off, use the same method to uncheck that option.
6. Without the setting

Here is an image of a code file without the setting. One cannot see tabs and spaces.
7. With the setting

Here is an image of a code file with the setting. One can see visual indicators of tabs and spaces.
8. End of page
9. Multiple choice questions for this page
4 questions omitted (login required)