在C#中不使用多少空格 [英] How many spaces does \t use in c#

查看:48
本文介绍了在C#中不使用多少空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用StringBuilder构建报告,并且将报告的详细信息适当地指定和对齐我将为此使用的

I am building a report using StringBuilder and the details of it to be properly intended and aligned for which i will be using

private static int paperWidth = 55; //it defines the size of paper
private static readonly string singleLine = string.Empty.PadLeft(paperWidth, '-');
StringBuilder reportLayout;
reportLayout.AppendLine("\t" + "Store Name");



我想在中心使用商店名称,并通过 \ t
来使用更多这样的字段预先感谢.



I want Store Name in center and many such more feilds by use of \t
Thanks in Advance.

编辑我想像打印.商店名称在中心

EDIT I want to print like. Store Name in center

推荐答案

如果要模拟终端上的选项卡,则应坚持每个选项卡 8个空格.制表符转移到下一个制表位.默认情况下,每8个空格中有一个.但是在大多数炮弹中您可以轻松地将其编辑为任意数量的空格

If you're simulating what tabs look like at a terminal you should stick with 8 spaces per tab. A Tab character shifts over to the next tab stop. By default, there is one every 8 spaces. But in most shells you can easily edit it to be whatever number of spaces you want

您可以通过以下代码实现这一点:

You can realize this through the following Code:

  string tab = "\t";
  string space = new string(' ', 8);
  StringBuilder str = new StringBuilder();
  str.AppendLine(tab + "A");
  str.AppendLine(space + "B");
  string outPut = str.ToString(); // will give two lines of equal length
  int lengthOfOP = outPut.Length; //will give you 15

在上面的示例中,我们可以说 .net 中 \ t 的长度为计算为 1

From the above example we can say that in .Net the length of \t is calculated as 1

这篇关于在C#中不使用多少空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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