C#String.PadLeft函数,文本对齐以及填补解决方案
来源:互联网 发布:ubuntu卸载virtualbox 编辑:程序博客网 时间:2024/06/05 00:38
由于很多时候我们需要把数据进行格式化,方便各个系统之间通信和数据交互,因此难免会经常让人位数不够而进行位数相应数据填充。比如,你希望获取的是7位的2进制数据格式,而2进制数据格式,都是以0,1都为数据信号的,只有1,0两数据格式,刚我说的是7位,相当于如下:1000101格式,如果,我的数据是101三个长度的2进制数据,但我想返回一个新的并且具有固定长度,位数不够填充0的做法。
string SourceStr="101";
string DestinationStr;
DestinationStr=String.PadLeft(7,"0");
Console.Write(DestinationStr);
以上代码就会输出:0000101
现在解析此函数,此函数有2个重载版本。
重载1:public string PadLeft(int totalWidth);
重载2public string PadLeft(int totalWidth, char paddingChar);
关于重载1的解释,微软的注释为:(这个默认是以空格进行左边填充,保持右边对齐。)
//
// Summary:
// Right-aligns the characters in this instance, padding with spaces on the
// left for a specified total length.
//
// Parameters:
// totalWidth:
// The number of characters in the resulting string, equal to the number of
// original characters plus any additional padding characters.
//
// Returns:
// A new System.String that is equivalent to this instance, but right-aligned
// and padded on the left with as many spaces as needed to create a length of
// totalWidth. Or, if totalWidth is less than the length of this instance, a
// new System.String object that is identical to this instance.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// totalWidth is less than zero.
public string PadLeft(int totalWidth);
而重载2的注释为:(可以根据自己想要填充的字符进行填充,对齐是字符串右对齐。)
- C#String.PadLeft函数,文本对齐以及填补解决方案
- C#String.PadLeft函数,文本对齐以及填补解决方案
- String.PadLeft()
- ASP等价于.NET里String对象的PadLeft和PadRight函数
- C# string.PadLeft &&String.PadRight方法
- css+js解决文本两端对齐以及分散对齐
- php str_pad字符串填补函数
- .Net FrameWork String.PadLeft() 、String.PadRight()、String.Substring()方法
- C语言中不安全的函数以及解决方案
- C语言中不安全的函数以及解决方案
- C语言中不安全的函数以及解决方案
- 在sql server中实现PadLeft函数
- 实现SQL SERVER 下的PadLeft函数
- CSS 文本域和按钮对齐不一致解决方案
- Java中实现String.padLeft和String.padRight
- 对齐文本
- 文本对齐
- 文本对齐
- Web开发中需要了解的东西
- HDOJ 1397:Goldbach's Conjecture 哈希加筛选法求素数
- 青岛最新公交线路一览(371-801)
- Sqlserver2005附加数据库时出错提示操作系统错误5120的解决办法
- Android常见问题收集
- C#String.PadLeft函数,文本对齐以及填补解决方案
- 项目总结
- notification chains 简介
- JVM类加载机制(ClassLoader)源码解析(1)
- android 中管理短信
- 通过【偷取此锁定】或【破除锁定】解锁SVN被锁定的文件的控制权
- 从菜鸟到高手的linux教程(三)
- vimdiff 少量文件合并,方便快捷
- 唤醒自己-你我共勉