C# String 前面不足位数补零的方法
int i=10;
方法1:Console.WriteLine(i.ToString("D5"));
方法2:Console.WriteLine(i.ToString().PadLeft(5,'0'));//推荐
方法3:Console.WriteLine(i.ToString("00000"));
在 C# 中可以对字符串使用 PadLeft 和 PadRight 进行轻松地补位。
PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度
PadLeft(int totalWidth, char paddingChar) //在字符串右边用 paddingChar 补足 totalWidth 长度
示例:
h = h.PadLeft(2, '0');
注意第二个参数为 char 类型,所以用单引号,也可以用 Convert.ToChar(string value) 把字符串转换成 char 类型。如果字符串长度大于 1,则使用 str.ToCharArray()[index]。
C# String 前面不足位数补零的方法的更多相关文章
- C# String 前面不足位数补零的方法 PadLeft
PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度PadLeft(int totalWid ...
- 【转】C# String 前面不足位数补零的方法
源地址:http://www.cnblogs.com/zhangqs008/archive/2012/02/01/2341078.html
- oracle不足位数补零的实现sql语句
select rpad('AAA',5,'0') from dual; 这样就可以了 [注意] 1.'AAA'为待补字符:5表示补齐后的总字符长度:0表示不足时补什么字符 2.rpad是右侧补0,左侧 ...
- java中int转String 固定位数 不足补零
转载自:http://ych0108.iteye.com/blog/2174134 String.format("%010d", 25); //25为int型 0代表前面要补的字符 ...
- java中int转成String位数不足前面补零
java中int转成String位数不足前面补零 转载自:http://ych0108.iteye.com/blog/2174134 java中int转String位数不够前面补零 String.fo ...
- 【c++基础】int转string自动补零
前言 使用to_string函数可以将不同类型的数据转换为string类,请参考here和here.如果string的位数固定,如何进行自动补零呢?请看本文实例! 代码 确定位数,to_string ...
- C#位数不足补零
C#位数不足补零:int i=10;方法1:Console.WriteLine(i.ToString("D5"));方法2:Console.WriteLine(i.ToString ...
- 047-PHP数字前面补零,固定位数补0
<?php #PHP 数字前面补零 固定位数补0 $num=128; $num=str_pad($num,8,"0",STR_PAD_LEFT); echo $num; // ...
- 时间戳位数不够13位,通过es6 的padEed补零
if(val.toString().length == 10){ val = val.toString().padEnd(13,"0")*1 //不够十三位放后面补零,超过13位也 ...
随机推荐
- jstl core 库 之 out set remove
jstl 核心库 out标签 out:输出的标签 * value :输出的值 * default :默认值 * escapeXml :是否转移 默认为true(转义) 代码: <!-- 输出常量 ...
- 【XLL 框架库函数】 TempInt/TempInt12
创建一个包含了 integer 的 XLOPER/XLOPER12 原型 LPXLOPER TempInt(short int i); LPXLOPER12 TempInt12(int i); 参数 ...
- SQL语句汇总
1.查询出来数据保留小数点2位,并且0.01时候,不会展示为.01. select to_char(0.1,'fm9999999990.00') from dual; 2.wm_concat ...
- sql面试题一 学生成绩
sql面试题一 学生成绩 原帖链接:http://topic.csdn.net/u/20081020/15/1ABF54D0-F401-42AB-A75E-DF90027CEBA0.html 表架 ...
- linux协议栈skb操作函数
- MVC 好记星不如烂笔头之 ---> 页面压缩GIP
public class BaseController : Controller { /// <summary> /// Called before the action method i ...
- OpenCV成长之路(2):图像的遍历
我们在实际应用中对图像进行的操作,往往并不是将图像作为一个整体进行操作,而是对图像中的所有点或特殊点进行运算,所以遍历图像就显得很重要,如何高效的遍历图像是一个很值得探讨的问题. 一.遍历图像的4种方 ...
- BlockingQueue深入分析(转)
1.BlockingQueue定义的常用方法如下 抛出异常 特殊值 阻塞 超时 插入 add(e) offer(e) put(e) offer(e,time,unit) 移除 remove() p ...
- 清华学堂 列车调度(Train)
列车调度(Train) Description Figure 1 shows the structure of a station for train dispatching. Figure 1 In ...
- LogPolar 对数极坐标
LogPolar 对数极坐标 cvLogPolar 对数极坐标(logpolar)是仿真生物视网膜中央凹陷的特性,具有数据压缩的能力,可用于目标跟踪中快速尺度和旋转变换不变的模板匹配. 对数极坐标其实 ...