C#中用PadLeft、PadRight 补足位数
在 C# 中可以对字符串使用 PadLeft 和 PadRight 进行轻松地补位。
PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度
PadRight(int totalWidth, char paddingChar) //在字符串右边用 paddingChar 补足 totalWidth 长度
示例:
h = h.PadLeft(2, '0');
注意第二个参数为 char 类型,所以用单引号,也可以用 Convert.ToChar(string value) 把字符串转换成 char 类型。如果字符串长度大于 1,则使用 str.ToCharArray()[index]。
C#中用PadLeft、PadRight 补足位数的更多相关文章
- 【转载】 C#中PadRight函数以特定字符在字符串结尾补足位数
在C#开发过程中字符串String类处理过程中,有时字符串长度不够时,需要在右侧侧指定特定的字符来补足字符串长度,此时可以使用String类下的PadRight方法对字符串结尾按特定的字符补足位数.M ...
- JS中的PadLeft、PadRight,位数不足,自动补位,String扩展方法
类似C#中的 PadLeft.PadRight方法 //方法一 function FillZero(p) { return new Array(3 - (p + '').length + 1).joi ...
- c# PadLeft,PadRight用法
补位 string str = "100"; str.PadLeft(5,'0') 输出:00100 str.PadRight(5, '0') 输出:10000
- VB6 padleft padright
Public Function PadLeft(ByVal s As String, ByVal i As Integer, ByVal c As String) If i > LenB( ...
- C#中PadLeft,PadRight的用法
今天在遇到一个需求的时候,需要一个字符串实现自增.是根据数据库中一个自增的int类型的值,实现自增的.但是要加上前缀.比如,数据库中有一个自增的值,为,2.那么这个自增的值后面的值就位3.4.5.6. ...
- printf格式输出数字,位数不够前面补0,适用与输出编号
printf格式输出数字,位数不够前面补0,适用与输出编号 printf格式输出:%[flags][width][.perc][F|N|h|l]type 用到了flags中的 0 (注意是零不是欧) ...
- C#字符串处理 及字符串格式化
本文来自:http://www.cnblogs.com/xuerongli/archive/2013/03/23/2976669.html string字符串是char的集合,而char是Unicod ...
- Excel使用技巧大全(超全)
目录 Excel 使用技巧集锦 --163 种技巧 一. 基本方法 1. 快速选中全部工作表 2. 快速启动 Excel 3. 快速删除选定区域数据 4. 给单元格重新命名 5. 在 Excel 中选 ...
- web开发过程中经常用到的一些公共方法及操作
进化成为程序猿也有段岁月了,所谓的经验,广度还是依旧,只不过是对于某种功能有了多种实现方式的想法.每天依旧不厌其烦的敲打着代码,每一行代码的回车似乎都有一种似曾相识的感觉.于是乎:粘贴复制,再粘贴再复 ...
随机推荐
- Day1 - Python基础1 介绍、基本语法、流程控制
Python之路,Day1 - Python基础1 本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼 ...
- Django runserver show client ip
get path of basehttp.py $ python >>> import site >>> site.getsitepackages() ['/usr ...
- [转载]使用兼容ie6 ie7 ie8 FF的text-overflow:ellips
使用兼容ie6 ie7 ie8 FF的text-overflow:ellipsis超出文本显示省略号来代替截取函数更有利于seo,如果使用截取函数,源代码中的标题是显示不完整的,即便是在title属性 ...
- 本地代码上传 -> Github
首先在控制台cd到你的本地项目,这里以teat为例 1.执行命令: git init 2.将项目文件添加到仓库中: git add . (可以是指定文件,将“.”转换为指定文件) 3.接下来com ...
- sublime text There are no packages 解决!
1.问题如下图 解决如下: 1.取得sublime.wbond.net的IPv4地址.在命令提示符中输入以下命令: ping sublime.wbond.net 获得 pv 4 ip 2.C ...
- cocos2d-x 音乐播放猜想
"SimpleAudioEngine.cpp": void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePa ...
- C++工厂方法模式
class IFactoryBase { public: IFactoryBase(void); virtual ~IFactoryBase(void); public: virtual IProdu ...
- oracle行转列和列转行
目录[-] 一.行转列 1.1.初始测试数据 1.2. 如果需要实现如下的查询效果图: 1.3.延伸 二.列转行 1.1.初始测试数据 1.2. 如果需要实现如下的查询效果图: 一.行转列 1.1.初 ...
- Linux imagemagic(转载)
原文地址:http://linux.chinaitlab.com/c/803455.html 更多详细使用示例请参考:http://www.ibm.com/developerworks/cn/open ...
- 【leetcode】62. Uniqe Paths
题目 https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...