static void Main()
{
string c=Console.ReadLine();
string d=Console.ReadLine();
Console.WriteLine(c+","+d); //用“+”連接符
}
static void Main()
{
string c=Console.ReadLine();
string d=Console.ReadLine();
string m=String.Format(“{0},{1}”,c,d); //字符串格式輸出
Response.Write(m);
}
C或c Currency 貨幣格式
D或d Decimal 十進制格式(十進制整數,不要和.Net的Decimal數據類型混淆了)
E或e Exponent 指數格式
F或f Fixed point 固定精度格式
G或g General 常用格式
N或n 用逗號分割千位的數字,比如1234將會被變成1,234
P或p Percentage 百分符號格式
R或r Round-trip 圓整(只用於浮點數)保證一個數字被轉化成字符串以后可以再被轉回成同樣的數字
X或x 16進制格式
protected void Page_Load(object sender, EventArgs e)
{
int i=12345;
Response.Write("{0:C}",i); //貨幣
Response.Write("{0:D}",i); //十進制數
Response.Write("{0:E}",i); //科學技術法
Response.Write("{0:F}",i); // 浮點數表示法
Response.Write("{0:G}",i); //G或g General 常用格式
Response.Write("{0:N}",i); //N或n 用逗號分割千位的數字
}
protected void Page_Load(object sender, EventArgs e)
{
string s1 = "三百";
string s2 = "1000";
string s3 = "2,000";
string s4 = "-1000";
string s5 = "4000d";
int currentValue = 0;
Response.Write(int.TryParse(s1, out currentValue)); //返回False
Response.Write(int.TryParse(s2, out currentValue)); //返回True
Response.Write(int.TryParse(s3, out currentValue)); //返回False
Response.Write(int.TryParse(s4, out currentValue)); //返回True
Response.Write(int.TryParse(s5, out currentValue)); //返回False
}
protected void Page_Load(object sender, EventArgs e)
{
string str = "Do you like ASP.NET?";
Response.Write(str.ToUpper()); //轉換為大寫
Response.Write(str.ToLower()); //轉換為小寫
}
d MM/dd/yyyy ShortDatePattern(短日期模式)
D dddd,MMMM dd,yyyy LongDatePattern(長日期模式)
F dddd,MMMM dd,yyyy HH:mm Full date and time (long date and short time)(全日期和時間模式)
F dddd,MMMM dd,yyyy HH:mm:ss FullDateTimePattern (long date and long time)(長日期和長時間)
G MM/dd/yyyy HH:mm General (short date and short time)(通用模式,短日期和短時間)
G MM/dd/yyyy HH:mm:ss General (short date and long time)(通用模式,短日期和長時間)
M,M MMMM dd MonthDayPattern(月天模式)
r,R ddd,dd MMM yyyy,HH':'mm':'ss 'GMT' RFC1123Pattern (RFC1123模式)
S yyyy-MM-dd HH:mm:ss SortableDateTimePattern (conforms to ISO 8601) using local time(使用本地時間的可排序模式)
T HH:mm ShortTimePattern (短時間模式)
T HH:mm:ss LongTimePattern(長時間模式)
U yyyy-MM-dd HH:mm:ss UniversalSortable-DateTimePattern (conforms to ISO 8601) using universal time(通用可排序模式)
U dddd,MMMM dd,yyyy,HH:mm:ss UniversalSortable-DateTimePattern(通用可排序模式)
y,Y MMMM,yyyy YearMonthPattern(年月模式)
static void Main()
{
Response.Write("{0:D}",DateTime.Now); //輸出到天
Response.Write("{0:y}",DateTime.Now); //輸出到月
Response.Write("{0:m}",DateTime.Now); //取出是那個月
Response.Write("{0:T}",DateTime.Now); // 取長時間到秒
Response.Write("{0:t}",DateTime.Now); //取短時間到分
Response.Write("{0:tt}",DateTime.Now); //取出是上午還是下午
}
