C#小方法PadLeft 和 PadRight


1.在 C# 中可以对字符串使用 PadLeft 和 PadRight 进行轻松地补位。

    PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度

    PadRight(int totalWidth, char paddingChar) //在字符串右边用 paddingChar 补足 totalWidth 长度

2.String.PadLeft(int length,char ReplaceStr):如果字符串的长度小于length,则在字符串的左边用ReplaceStr填充。  

实例:         string num=12         num.PadLeft(4, '0'); //结果为为 '0012'        //看字符串长度是否满足4位,不满足则在字符串左边以"0"补足


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM