c#用的String问题 怎么可以把一个少于两个字符数转化为两个字符比如 0 10 02 123 2 转化为 00 10 02 123 02 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int panda = 1; Console.WriteLine(panda.ToString("D2"));//结果01 public string FormatString(string str){ if(str.length==1) { str = "0" + str; } return str;} string str = "1";Console.WriteLine(str.PadLeft(2, '0')); int panda = 1; Console.WriteLine(panda.ToString("D2"));//结果01顶 str=str.PadLeft(1, '0')//当只有1位长度时 补充1位0; if(1==str.length){ str.PadLeft(2, '0');} 迟到如果总长度固定的话:String..::.PadRight 方法 (Int32, Char) 參數 totalWidth 型別:System..::.Int32 產生的字串中的字元數,等於原始字元加上任何其他填補字元的數目。 paddingChar 型別:System..::.Char Unicode 填補字元。 傳回值 型別:System..::.String 新的 String,對等於這個執行個體,但是靠左對齊,並在右側填補必要的 paddingChar 字元,以建立 totalWidth 的長度。如果 totalWidth 小於這個執行個體的長度,則為與這個執行個體相同的新 String。 範例 C# code string str = "forty-two";char pad = '.';Console.WriteLine(str.PadRight(15, pad)); // Displays "forty-two......".Console.WriteLine(str.PadRight(2, pad)); // Displays "forty-two". C# 读取数组元素 sql 查询 小问题 请教 请问怎样获取选项卡页内的控件呢? 请各位前辈推荐一下表示软件内部逻辑关系的软件,先感谢了! 新手请教一个有关接口的简单问题(10分) 【100分求解】图片移动起来闪呀闪呀闪。。。。 如何实现重新登陆功能~~??? Excel轉化成Datatable_高分求 使用npoi 操作excel 保存后没有写入 想知道谁对mshtml进行过比较彻底的研究 请教则个 求助!!水晶報表中分頁顯示問題。。。急 我把flash放到窗体程序后,安装部署后。文件夹里还是有flash文件 能否不让flash文件显示出来!??变成dll 什么的类型
public string FormatString(string str)
{
if(str.length==1)
{
str = "0" + str;
}
return str;
}
Console.WriteLine(str.PadLeft(2, '0'));
顶
if(1==str.length)
{
str.PadLeft(2, '0');
}
如果总长度固定的话:
String..::.PadRight 方法 (Int32, Char) 參數
totalWidth
型別:System..::.Int32 產生的字串中的字元數,等於原始字元加上任何其他填補字元的數目。 paddingChar
型別:System..::.Char Unicode 填補字元。 傳回值
型別:System..::.String 新的 String,對等於這個執行個體,但是靠左對齊,並在右側填補必要的 paddingChar 字元,以建立 totalWidth 的長度。如果 totalWidth 小於這個執行個體的長度,則為與這個執行個體相同的新 String。 範例
C# code
string str = "forty-two";
char pad = '.';Console.WriteLine(str.PadRight(15, pad)); // Displays "forty-two......".
Console.WriteLine(str.PadRight(2, pad)); // Displays "forty-two".