输出的文本实现对齐的方法(超简单)
作者:杨明波(Leo Yang) 时间:2023-06-19 03:57:09
在本博客中,可以找到一篇《c#实现输出的字符靠右对齐的示例》
它有教大家怎样实现字符串输出进行左齐或者是右对齐。
本篇的方法,超简单,是使用string.Format()对本进行格式化输出即可。
Source Code
class Ad
{
private string[] myVar;
public Ad(string[] myValue)
{
this.myVar = myValue;
}
public void PadLeft()
{
foreach (string s in this.myVar)
{
string s2 = String.Format("{0,13}", s);
Console.WriteLine(s2);
}
}
}
上面的数字“13”就是占位符,正数是靠右对齐,反之,负数是靠左对齐:
来源:http://www.cnblogs.com/insus/p/7992267.html
标签:输出,文本,对齐
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一篇文章弄懂Java8中的时间处理
2022-07-22 07:56:32
![](https://img.aspxhome.com/file/2023/3/119203_0s.png)
SpringBoot打jar包遇到的xml文件丢失的解决方案
2023-04-11 23:39:06
![](https://img.aspxhome.com/file/2023/4/66174_0s.png)
Springboot集成Elasticsearch的步骤与相关功能
2022-07-23 06:47:30
![](https://img.aspxhome.com/file/2023/8/70488_0s.png)
JavaWeb Servlet生命周期细枝末节处深究
2023-08-25 22:48:23
Java建造者模式构建复杂对象的最佳实践
2021-06-27 10:07:16
![](https://img.aspxhome.com/file/2023/8/61808_0s.png)
SpringCloud高可用配置中心Config详解
2023-11-17 11:25:00
![](https://img.aspxhome.com/file/2023/1/94211_0s.png)
SpringBoot的异常处理流程是什么样的?
2021-07-09 17:54:40
![](https://img.aspxhome.com/file/2023/4/81894_0s.png)
Linux下java环境配置图文方法
2021-10-24 06:22:52
![](https://img.aspxhome.com/file/2023/0/70300_0s.png)
Android调用系统默认浏览器访问的方法
2022-04-02 12:14:52
JAVA关键字及作用详解
2022-05-03 03:50:14
Java中Excel高效解析工具EasyExcel的实践
2023-05-28 13:36:38
![](https://img.aspxhome.com/file/2023/9/86059_0s.webp)
java使用common-fileupload实现文件上传
2022-03-06 03:21:08
C#中隐式运行CMD命令行窗口的方法
2021-06-11 18:47:07
Android中实现Webview顶部带进度条的方法
2022-04-22 15:45:43
![](https://img.aspxhome.com/file/2023/2/116142_0s.png)
SpringBoot整合MybatisPlus实现增删改查功能
2022-10-31 05:24:15
![](https://img.aspxhome.com/file/2023/8/65728_0s.png)
springboot中使用redis并且执行调试lua脚本
2022-02-15 08:49:52
![](https://img.aspxhome.com/file/2023/1/61031_0s.png)
Springboot使用POI实现导出Excel文件示例
2021-09-22 08:18:31
![](https://img.aspxhome.com/file/2023/8/61398_0s.jpg)
Spring-Security对HTTP相应头的安全支持方式
2021-07-25 16:30:55
Android编程之文件读写操作与技巧总结【经典收藏】
2023-10-16 02:20:52
Java反射及性能详细
2023-08-20 20:49:42
![](https://img.aspxhome.com/file/2023/2/72532_0s.png)