截取字符串

int i=10;
方法1:Console.WriteLine(i.ToString("D5"));
方法2:Console.WriteLine(i.ToString().PadLeft(5,'0'));//推荐
方法3:Console.WriteLine(i.ToString("00000")); 

String.PadLeft 方法 
[C#]请参见
String 类 | String 成员 | System 命名空间
右对齐此实例中的字符,在左边用空格或指定的 Unicode 字符填充以达到指定的总长度。
重载列表

(一)右对齐此实例中的字符,在左边用空格填充以达到指定的总长度。

[Visual Basic] Overloads Public Function PadLeft(Integer) As String
[C#] public string PadLeft(int);
[C++] public: String* PadLeft(int);
[JScript] public function PadLeft(int) : String;

(二)右对齐此实例中的字符,在左边用指定的 Unicode 字符填充以达到指定的总长度。

[Visual Basic] Overloads Public Function PadLeft(Integer, Char) As String
[C#] public string PadLeft(int, char);
[C++] public: String* PadLeft(int, __wchar_t);
[JScript] public function PadLeft(int, Char) : String;

文件重新命名

 static void Main(string[] args)
        {
            string path = @"d:4.txt"; //源文件
            string path2 = @"d:move13.txt";//移动到哪里
            if (MoveFile(path, path2))
                Console.WriteLine("success");
            else
                Console.WriteLine("bad");

            Console.WriteLine();
        }
        private static bool MoveFile(string OldPath, string MoveNewPath)
        {
            Boolean IsSuccess = false;//状态

            try
            {
                if (!File.Exists(OldPath))//判断路径是是否存在
                {
                    Console.WriteLine("不存在,正在创建");
                    using (FileStream fs = File.Create(OldPath)) { } //创建文件
                }
                if (!File.Exists(MoveNewPath))//判断路径是是否存在
                {
                    Console.WriteLine("不存在,正在创建");
                    using (FileStream fs = File.Create(MoveNewPath)) { } //创建文件
                }
                if (File.Exists(MoveNewPath))
                {
                    Console.WriteLine("原目录有相同的文件,/r是否覆盖该文件,确定:Y 取消输入:N");
                    string inputVlaue = Console.ReadLine();
                    switch (inputVlaue.ToUpper())
                    {
                        case "Y":
                            File.Delete(MoveNewPath);
                            File.Move(OldPath, MoveNewPath);
                            IsSuccess = true;
                            Console.WriteLine("成功将{0}move到{1}.", OldPath, MoveNewPath);
                            break;
                        case "N":
                            IsSuccess = false;
                            break;
                        default:
                            Console.WriteLine("输入有误");
                            break;
                    }
                }
                else
                {
                    File.Move(OldPath, MoveNewPath);
                    IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The process failed: {0}", e.ToString());
            }
            return IsSuccess;
        }
原文地址:https://www.cnblogs.com/tested/p/3287076.html