------------------------
★字符串截取
String.SubString(int n);//截取从索引n开始后面的字符串。
String.SubString(int n,int m);//截取索引n到索引m的字符串
★分隔字符串
string[] s = strs.Split('.'); //按'.'符号将字符串分隔成数组
★去掉字符串头尾的空格:str.Trim();
★去除字符串中的空格:Replace方法:str.Replace(" ","");
★删除字符串中某些字符:
string x = "abcdefg";
string y = Regex.Replace(x, @"[beg]", "").ToString();//beg为指定需要删除的
Console.WriteLine(y); //y="acdf";
★字符串转换货币格式;
先转换成int或double 在用String.Format("{0:C}", nt)
★获取字符串中的指定字符 的最后出现的后面的字符串
string fname = @"//10.201.51.26/IMAGESHARE/GROUPWARE/1004/20070524_143518.XLS ";
fname = fname.Substring(fname.LastIndexOf('//') + 1);//“20070524_143518.XLS”
fname =fname.Substring(0,fname.LastIndexOf('//'));//"//10.201.51.26
/IMAGESHARE/GROUPWARE/1004
------------------------
★//获取不重复随机数
int temp = 0; int[] intArr = new int[100]; ArrayList myList = new ArrayList(); Random rnd = new Random(); while (myList.Count < 100) { int num = rnd.Next(1, 101); if (!myList.Contains(num)) //判断数组中是否存在这个元素 myList.Add(num); } // 转换为整形数组 for (int i = 0; i < 100; i++) intArr[i] = (int)myList[i]; //排序 for (int i = 0; i < intArr.Length-1; i++) { for (int j = 0; j < intArr.Length-1; j++) { if(intArr[j] > intArr[j+1]) { temp = intArr[j + 1]; intArr[j + 1] = intArr[j]; intArr[j] = temp; } } }
------------------------
★DateTime时间类型大小比较
DateTime TopTime = new DateTime(2010, 1, 1, 15, 36, 05);//时间转换
DateTime LowTime = new DateTime(2004, 3, 1, 20, 16, 35);
DateTime XFtime=Convert.ToDateTime("2010-10-10 10:10:10");
TimeSpan TempTimeSpan = TopTime-LowTime;
ReturnStr = ((int)(ts.TotalSeconds)).ToString() + "秒前";
ReturnStr = ((int)(ts.TotalMinutes)).ToString() + "分钟前";
ReturnStr = ((int)(ts.TotalHours)).ToString() + "小时前";
"相差:"+ TempTimeSpan.Days.ToString() + "天"+ TempTimeSpan.Hours.ToString() + "小时"+
TempTimeSpan.Minutes.ToString() + "分钟" +TempTimeSpan.Seconds.ToString() + "秒";
------------------------
★
------------------------
★
------------------------
★
------------------------
★
------------------------
★
------------------------