C# 常用小点
1】创建文件夹
//相对路径 string FilePath = Server.MapPath("./") + "ImageFile/Images/" + DateTime.Now.Year.ToString() + "Year/" + DateTime.Now.Month.ToString() + "Month/"; DirectoryInfo di = new DirectoryInfo(FilePath); if (!di.Exists)//如果没有就创建 {di.Create();} //绝对路径 string receivePath = @"C:/ImageFile/Images/" + DateTime.Now.Year.ToString() + "Year/" + DateTime.Now.Month.ToString() + "Month/"; DirectoryInfo di = new DirectoryInfo(receivePath); if (!di.Exists) { di.Create(); }
2】分割字符串
var getStr = Str.Split(new string[] { "$tempId$" }, StringSplitOptions.None);
3】去除字符串中,指定字符的最后一个
string Name ="asdsa,asdsa,21321," Name = Name .TrimEnd(','); //输出之后 asdsa,asdsa,21321