C#输出文字对齐,空格位数对齐
Align String with Space
This example shows how to align strings with spaces. The example formats text to table and writes it to console output.
To align string to the right or to the left use static method String.Format. To align string to the left (spaces on the right) use formatting patern with comma (,) followed by a negative number of characters: String.Format(„{0,–10}“, text). To right alignment use a positive number: {0,10}.
Following example shows how to format text to the table. Values in the first and second column are aligned to the left and the third column is aligned to the right.
[C#]
Console.WriteLine("-------------------------------");
Console.WriteLine("First Name | Last Name | Age");
Console.WriteLine("-------------------------------");
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Bill", "Gates", 51));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Edna", "Parker", 114));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Johnny", "Depp", 44));
Console.WriteLine("-------------------------------");
Output string:
-------------------------------
First Name | Last Name | Age
-------------------------------
Bill | Gates | 51
Edna | Parker | 114
Johnny | Depp | 44
-------------------------------
C#输出文字对齐,空格位数对齐的更多相关文章
- 关于checkbox与文字混排无法对齐的解决方法
先前代码如下 <span style="vertical-align:middle"><input type="checkbox" name ...
- inline-block 文字与图片不对齐
文字旁边搭配图片时,发现图片比文字靠上,原来默认的情况是图片顶对齐而文字底对齐,通过设置css属性可以使得图片与文字对齐. 设置各对象的vertical-align属性,属性说明: baseline- ...
- 测开之路九十三:css之文字样式和段落对齐
引用css 字体族 字体类型和尺寸 em:字体按倍数缩放 font-weight:调整文字的粗细 段落对齐:text-align 左对齐:left 右对齐:right 居中对齐:center 两边对齐 ...
- 音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系
音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系 原创 2014年02月11日 13:56:51 4951 0 0 刚刚过完春节,受假期综合症影响脑袋有点发 ...
- iOS的UILabel设置居上对齐,居中对齐,居下对齐
在iOS中默认的UILabel中的文字在竖直方向上只能居中对齐,博主参考国外网站,从UILabel继承了一个新类,实现了居上对齐,居中对齐,居下对齐.具体如下: // // myUILabel.h ...
- 【css基础】文本对齐,水平对齐,垂直对齐
先说水平对齐,那首先想到的就是text-align了,text-align:left,text-align:center,text- align:right,代表的就是左对齐,居中对齐和右对齐,需要注 ...
- iOS UILabel设置居上对齐,居中对齐,居下对齐
在iOS中默认的UILabel中的文字在竖直方向上仅仅能居中对齐,博主參考国外站点.从UILabel继承了一个新类,实现了居上对齐,居中对齐,居下对齐.详细例如以下: // // myUILabel ...
- mfc主窗口添加背景图片后,如何实现在背景图片上输出文字
1.若是文档视图程序的话,在视图类的OnDraw(CDC* pDC)函数中调用pDC->TextOut()函数,就像平常输出文字一样.若是嫌文字的背景颜色破坏了图像,可以在输出文字之前调用pDC ...
- Eclipse设置Tab键缩进4个空格的步骤,也就是按一下Tab键输出四个空格
Eclipse设置Tab键缩进4个空格的步骤,也就是按1下Tab键输出4个空格,步奏如下 1.点击 window->preference-,选择 General->Editors-> ...
随机推荐
- 操作系统课程设计--Linux平台哲学家问题
哲学家问题是操作系统中资源分配的经典问题 linux平台下的系统api不同于Windows下的实现 要求:一个正确的哲学家程序(不会发生死锁) 一个错误的哲学家程序(会发生死锁) 系统环境:Eleme ...
- 使用ROW_NUMBER()+临时表+While 实现表遍历
declare @table table(dlid int,RowNum int)insert into @table select dlid,ROW_NUMBER() over(order by d ...
- Coding List
决定还是用回.net吧,一个人瞎搞比较快,在这里把进展做个简单的记录.
- 设置html title标题左侧的小图标
网页title旁边的小图片设置,图片要求格式必须是.ico,可以使用在线的转换工具把jpg和png图片转换为ico图片,工具地址:http://www.ico.la/ 在html文件中的<hea ...
- jquery.extend
经常在插件中看到jquery.extend 方法,最近在尝试写一些简单的插件,顺便研究一下这个方法. 原文:http://www.cnblogs.com/RascallySnake/archive/2 ...
- jQuery checkbox的全选与反选
1:checkbox的全选与反选 js 代码 $("#cbAll").click(function(){ if($("#cbAll").is(":ch ...
- 记一次proc_open没有开启心得感悟
引言: 今天在部署服务器的时候,使用composer来安装依赖.遇到了 The Process class relies on proc_open, which is not available on ...
- C 标准库系列之locale.h
locale.h 区域设置相关,主要针对时间日期.货币格式.字符控制.数字格式等以满足某区域的设置需要. locale设置类别主要包括以下几个宏定义的类别: LC_ALL:设置所有的类别: LC_CO ...
- 在Mac上开启自带的Apache,httpd服务
下面演示的是Mac自带的httpd服务 启动httpd服务 AppledeMacBook-Pro:python2_zh apple$ sudo apachectl start AppledeMacBo ...
- 【转载】VS2012的打包方法
上篇博客把收费系统的总体设计进行了一遍讲解,讲解的同时掺杂了些有关.NET编译机制的总结.程序编写测试完成后接下来我们要做的是打包部署程序,但VS2012让人心痛的是没有了打包工具.不知道出于什么原因 ...