C#中补0
编写人:CC阿爸
2014-3-16
首先先增加两个左补齐又补齐的函数
#region 该函数动态添加空格,对齐小票 public string AddSpace(string text, int length) { //左对齐此字符串中的字符,在右边用空格或指定的 Unicode 字符填充以达到指定的总长度。 text = text.PadRight(length, ' '); return text; } public string AddSpaceBefore(string text, int length) { //左对齐此字符串中的字符,在左边用空格或指定的 Unicode 字符填充以达到指定的总长度。 text = text.PadLeft(length,' '); return text; } #endregion
用到的两函数
使用方法:
sw.WriteLine(AddSpace(ds.Tables[].Rows[]["PrintHead"].ToString(), ) + "\t\t");