1. 程式人生 > 其它 >crontab——定時任務

crontab——定時任務

技術標籤:c#入門字串c#

字串的擷取、分割、插入、複製、刪除

字串的擷取

            string id = "12345619997890";
            string brithdate1 = id.Substring(6);//
            string brithdate2 = id.Substring(6, 4);
            string fileName = "Program.cs";
            string strName = fileName.Substring(0, fileName.
IndexOf('.')); string strExtension = fileName.Substring(fileName.IndexOf('.')); Console.WriteLine(brithdate1); Console.WriteLine(brithdate2); Console.WriteLine(strName); Console.WriteLine(strExtension);

在這裡插入圖片描述

字串的分割

                   string strName =
"hello,world,vs"; string[] strArry1 = strName.Split(new char[] { ',' }); string[] strArry2 = strName.Split(new char[] { ',' },2); for(int i = 0; i < strArry1.Length; i++) { Console.WriteLine
(strArry1[i]); } for (int i = 0; i < strArry2.Length; i++) { Console.WriteLine(strArry2[i]); }*

在這裡插入圖片描述

字串的插入

            string strOld = "Keep on never give up.";
            string strNew = strOld.Insert(8, "going ");
            Console.WriteLine(strNew);

在這裡插入圖片描述

字串的刪除

            string strOld = "hellovsworld";
            string strNew1 = strOld.Remove(5);
            string strNew2 = strOld.Remove(5,2);
            Console.WriteLine(strNew1);
            Console.WriteLine(strNew2);

在這裡插入圖片描述

字串的複製

            string strOld = "Keep on going never give up.";
            string strNew1 = string.Copy(strOld);
            Console.WriteLine(strNew1);
            char[] strNew2=new char[5];
            strOld.CopyTo(strOld.IndexOf("never"),strNew2,0, 5);
            Console.WriteLine(strNew2);

在這裡插入圖片描述

字串的替換

            string str1 = "hello world";
            string replaceStr1 = str1.Replace('h', 'H');
            string str2 = "hello world";
            string replaceStr2 = str2.Replace("hello","HELLO");
            Console.WriteLine(replaceStr1);
            Console.WriteLine(replaceStr2);

在這裡插入圖片描述