How to detect a tab in a text file?

Is tab detection the same as gap detection? that is, to detect a space, I would simply compare the space character with its ascii number.

For the tab, should I look for the '\ t' character in the file, or is there some other way?

+5
source share
4 answers

Assuming you are working with ASCII data, you can simply search for a byte with a value of '\ t' (9) in a text file. The tabs are represented as a single byte in text files, and most libraries for reading files do nothing special with these bytes.

+3
source
if('\t' == myChar)

, 9, 9 .

+5

The tab is another character, so you can check the ASCII value if you want.

+1
source

Although the tab appears as 4 or 8 spaces in the editor, it actually appears as a single character ('\ t', as you mentioned) inside the file. Both space characters and the tab character occupy one byte. Thus, in principle, you are right in your assumption.

+1
source

All Articles