2006-10-26 14:04:41心靈季動
String多樣化
煩人的字串.....總是需要取幾個字元或是加符號...
有的沒有....把常用的收集起來,這樣要找就快多了
★不足三位前面會補零,結果為0123
int i = 123;
Response.Write(i.ToString(”0000”));
★將日期 20061026 改成 2006/10/26
string strDate = ”20061016”;
strDate = strDate.Insert(4,”/”).Insert(7,”/”);
★將字串切開,用Split
string strid = ”2,3,5,6”;
string[] strList = strid.Split(’,’);
foreach (string j in strList)
{
Response.Write(j + ”
”);
}
或
for (int i = 0; i < strList.Length; i++)
{
Response.Write(strList[i] + ”
”);
}
★將數字12345變成12,345
string num = ”12345”;
num = string.Format(”{0:#,##}”, Convert.ToInt32(num));
有的沒有....把常用的收集起來,這樣要找就快多了
★不足三位前面會補零,結果為0123
int i = 123;
Response.Write(i.ToString(”0000”));
★將日期 20061026 改成 2006/10/26
string strDate = ”20061016”;
strDate = strDate.Insert(4,”/”).Insert(7,”/”);
★將字串切開,用Split
string strid = ”2,3,5,6”;
string[] strList = strid.Split(’,’);
foreach (string j in strList)
{
Response.Write(j + ”
”);
}
或
for (int i = 0; i < strList.Length; i++)
{
Response.Write(strList[i] + ”
”);
}
★將數字12345變成12,345
string num = ”12345”;
num = string.Format(”{0:#,##}”, Convert.ToInt32(num));