how many spaces is a tab?

how many spaces is a tab

Tab key in the keyboard which is char(9) of ASCII, is a useful key with a lot of functions in our systems, we use it alone to move the focus to the next object, or with [Alt] key to switch between applications, sometimes with [Ctrl] to switch between tabs, some times we use it in text editors to arrange data or text in a tabular, or table, form.

how many spaces is a tab?

While I was searching for some codes I found this question, also I found a lots of great answers, the common answer was 8 characters for each tab, most of people agree with that.

But from my aspect I have different answer, first let us describe how tab makes spaces between words.
This function only apply with text editor such as document management software or programming code environment, each software consist of many objects such as buttons, frames, check boxes and text objects, each object of them has its own data and properties loaded and stored into memory and that includes text objects, tab key like other characters stored in memory as one ascii number, see how my simple code store in memory:

tab key stored in memory

So tab key is just one character which is number(9) in ASCII, but text object transform this code to a number of space which is not fixed, it only complete the remaining space to move to the next start position to make text in a tabular form.

tab key move cursor to next position

Different tab spaces for different editor software.

Each text management software treats different from others, some of them count 4 spaces for next start position while others count 8, one of my editors count 8 spaces for text files and count 4 for php files ,I could build my own text editor and make tab key count 5 characters for every next start position.

different spaces for each text editor

Where is the next position after tab key?

Tab moves cursor to the next virtual column in the text editors,
If tab count 8 spaces, the next position will be (Next_Column * 8)+1, so the sequence will be(1,9,17,25,...).
If tab count 4 spaces, the next position will be (Next_Column * 4)+1, so the sequence will be(1,5,9,13,...).

Programming Code Indentation

Text editors or Programming IDE uses tab key to arrange the code and make it readable like this Example code

// Here you will find 8 chars spaces for every tab.
function PrintResult(id){
var StudentName;
var StudentDOB;
var StudentTelephone;
var StudentCity;

 //select Studentdata from DataBase
 if (StudentExist)
  print ("StudentName");
  print ("StudentDOB");
  print ("StudentTelephone");
  print ("StudentCity");
  print ("Student id doesn't exist !");

If this post was good and helpful for you, Please give it Like.
    Blogger Comment
    Facebook Comment


Post a Comment