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();
                }
View Code

 

2】分割字符串

 var getStr = Str.Split(new string[] { "$tempId$" }, StringSplitOptions.None);
View Code

 

3】去除字符串中,指定字符的最後一個

string Name ="asdsa,asdsa,21321,"
 Name = Name .TrimEnd(',');

//輸出以後
asdsa,asdsa,21321
相關文章
相關標籤/搜索