小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

C#字符串類String的使用(二)

 路人甲Java 2021-03-21
格式化字符串
 //格式化字符串
            //一個(gè)靜態(tài)的Format方法,用于將字符串?dāng)?shù)據(jù)格式化成指定的格式
            string newstr = String.Format("{0},{1}!!!", str1, str2);
            Console.WriteLine(newstr);
            Console.ReadLine();
 //Format方法將日期格式格式化成指定格式
            DateTime dt = DateTime.Now;
            string strb = String.Format("{0:D}", dt);
            Console.WriteLine(strb);
            Console.ReadLine();

截取字符串
 //截取字符串
            //Substring 該方法可以截取字符串中指定位置的指定長度的字符串
            //索引從0開始截取三個(gè)字符
            string a = "zhzfdx@qq.com";
            string b = "";
            b = a.Substring(0, 3);
            Console.WriteLine(b);
            Console.ReadLine();
分割字符串
//分割字符串
            //Split 用于分割字符串,此方法的返回值包含所有分割子字符串的數(shù)組對(duì)象
            //可以通過數(shù)組取得所有分割的子字符串
            string a = "zhzfdx@qq.com";
            string[] splitstrings = new string[100];
            char[] separator = { '@', '.' };
            splitstrings = a.Split(separator);
            for(int i = 0; i < splitstrings.Length; i++)
            {
                Console.WriteLine("item{0}:{1}", i, splitstrings[i]);
            }
            Console.ReadLine();
插入和填充字符串
//插入和填充字符串
            //Insert方法 用于向字符串任意位置插入新元素
            //插入
            string a = "zhz";
            string b;
            b = a.Insert(3, "fdx@qq.com");
            Console.WriteLine(b);
            Console.ReadLine();
//PadLeft/PadRight方法用于填充字符串
            //PadLeft方法是在字符串左側(cè)進(jìn)行字符填充
            //PadRight方法是在字符串右側(cè)進(jìn)行字符填充
            //注意:字符填充?。?!
            string a = "";
            string b = a.PadLeft(1, 'z');
            b = b.PadRight(2, 'h');
            Console.WriteLine(b);
            Console.ReadLine();
刪除字符串
 //刪除字符串
            //Remove 方法從一個(gè)字符串指定位置開始,刪除指定數(shù)量的字符

            string a = "zhzfdx@qq.com";
            string b = a.Remove(3);
            string c = a.Remove(3, 3);
            Console.WriteLine(b);
            Console.WriteLine(c);
            Console.ReadLine();
復(fù)制字符串

            //復(fù)制字符串
            //Copy和CopyTo方法
            //Copy用于將字符串或子字符串復(fù)制到另一個(gè)字符串或Char類型的數(shù)組中
            //CopyTo可以將字符串的某一部分復(fù)制到另一個(gè)數(shù)組中
            //Copy
            string a = "zhzfdx@qq.com";
            string b;
            b = String.Copy(a);
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.ReadLine();

            //CopyTo
            char[] str = new char[100];
            //3:需要復(fù)制的字符的起始位置3
            //str:目標(biāo)數(shù)組
            //0:目標(biāo)數(shù)組中開始存放的位置0
            //10:復(fù)制字符的個(gè)數(shù)
            a.CopyTo(3, str, 0, 10);
            Console.WriteLine(str);
            Console.ReadLine();
替換字符串
  //替換字符串
            //Replace方法
            //將字符串中的某個(gè)字符或字符串替換成其他字符或字符串

            string a = "zzzhhhzzz";
            string b = a.Replace('z', 'x');
            Console.WriteLine(b);
            string c = a.Replace("zzzhhhzzz", "fffdddxxx");
            Console.WriteLine(c);
            Console.ReadLine();

未完待續(xù)。。。。。。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多