制表符(\t)有多少空格? [英] How many spaces for tab character(\t)?

查看:1094
本文介绍了制表符(\t)有多少空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现文本绘图功能。但是我不确定 \t 的工作方式,这意味着我不知道应该为 \t

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.

我想出了以下算法:

a)每个 \t 最多表示 NUMBER_OF_SPACES_FOR_TAB 个空格。
b)如果 \t 出现在最后一行的相应位置,则 \t 行应与最后一行的 \t 对齐。

a) Each \t represents at most NUMBER_OF_SPACES_FOR_TAB spaces. b) If \t appears in the last line at a corresponding position, \t for this line should be aligned to the \t of last line.

示例:

printf("a\t\tb\n");
printf("\t\tc\n");

应打印:

a11112222b
34444c

其中:

1.Number i 表示位置<$ c处 \t 的空格$ c> i

1.Number i represents the spaces of \t at position i

2。 NUMBER_OF_SPACES_FOR_TAB == 4

有人知道标准算法吗?

Does anyone know the standard algorithm? Thanks in advance.

推荐答案

制表符应前进到下一个制表位。从历史上看,制表位是每8个字符,尽管今天较小的值是常用的,并且可以配置大多数编辑器。

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

算法是将列计数从零开始,然后为每个字符输出递增。转到选项卡时,输出 n-(c%n)空格,其中 c 是列号(零基于),而 n 是制表符间距。

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.

这篇关于制表符(\t)有多少空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆