How many spaces for tab character(\t)?

前端 未结 3 502
粉色の甜心
粉色の甜心 2020-12-05 05:02

I want to implement a text drawing function. But I am not sure how \\t works, which means I don\'t know how many spaces I should print for \\t.

3条回答
  •  再見小時候
    2020-12-05 05:45

    A tab character should advance to the next tab stop. Historically tab stops were every 8th character, although smaller values are in common use today and most editors can be configured.

    I would expect your output to look like the following:

    123456789
    a       b
            c
    

    The algorithm is to start a column count at zero, then increment it for each character output. When you get to a tab, output n-(c%n) spaces where c is the column number (zero based) and n is the tab spacing.

提交回复
热议问题