字符串处理
来源:百度文库 编辑:神马文学网 时间:2024/05/09 19:51:54
str.padleft(n,'*')重复输出
string str = "中国加油!";
str.Dayofweek()为星期几
str.tostring('yyyy年mm月dd日')
Response.Write(str.IndexOf("中国").ToString());//取相同字符的索引
Response.Write(str.Insert(2,"河南"));//插入
Response.Write(str.Remove(0,2));//移除
Response.Write(str.Replace("中国", "河南"));//替换
Response.Write(str.Substring(0,2));//可以用来截取身份证号获取生日
Response.Write(str.Trim());//去除两端空格
日期处理:
DateTime Mydate = new DateTime(2010,4,24);
DateTime Date1 = Mydate.AddHours(-36.3669);
DateTime Date2 = Date1.AddMonths(23);
Response.Write(Date1.ToString()+"
"+Date2.ToString());DateTime time1 = new DateTime(2010,4,24,16,48,46);
Response.Write(time1.ToString("d"));//为短日期形式只显示日期不显示时间
Response.Write(time1.ToString("dddd HH:mm:ss"));//输出星期,时间
Response.Write(time1.ToString("yy年MM月dd日"));//输出日期
数据类型处理:
byte a = 15;//单字节变量
short b = a;//微精度变量
int c = b;//整型
long d = c;//长整型
float e = d;//浮点数
double q = e;//双精度
把字符串转换为数组:
string Mydata = "hello world";
char[] data = Mydata.ToCharArray();
Response.Write(data[0]); string Mydata = "hello\\world";
string [] data = Mydata.Split('\\');//用截取字符串的方式
Response.Write(data[0].ToString());
string str = "中国加油!";
str.Dayofweek()为星期几
str.tostring('yyyy年mm月dd日')
Response.Write(str.IndexOf("中国").ToString());//取相同字符的索引
Response.Write(str.Insert(2,"河南"));//插入
Response.Write(str.Remove(0,2));//移除
Response.Write(str.Replace("中国", "河南"));//替换
Response.Write(str.Substring(0,2));//可以用来截取身份证号获取生日
Response.Write(str.Trim());//去除两端空格
日期处理:
DateTime Mydate = new DateTime(2010,4,24);
DateTime Date1 = Mydate.AddHours(-36.3669);
DateTime Date2 = Date1.AddMonths(23);
Response.Write(Date1.ToString()+"
"+Date2.ToString());DateTime time1 = new DateTime(2010,4,24,16,48,46);
Response.Write(time1.ToString("d"));//为短日期形式只显示日期不显示时间
Response.Write(time1.ToString("dddd HH:mm:ss"));//输出星期,时间
Response.Write(time1.ToString("yy年MM月dd日"));//输出日期
数据类型处理:
byte a = 15;//单字节变量
short b = a;//微精度变量
int c = b;//整型
long d = c;//长整型
float e = d;//浮点数
double q = e;//双精度
把字符串转换为数组:
string Mydata = "hello world";
char[] data = Mydata.ToCharArray();
Response.Write(data[0]); string Mydata = "hello\\world";
string [] data = Mydata.Split('\\');//用截取字符串的方式
Response.Write(data[0].ToString());