C# 字符串操作

            //*******************【split】**********************
            string str = "yyyy-MM-dd";
            string[] splitArray = str.Split('-'); //splitArray[0]:yyyy splitArray[1]:MM splitArray[2]:dd

            string str1 = "yyyy_MM-dd"; //splitArray[0]:yyyy splitArray[1]:MM splitArray[2]:dd
            string[] splitArray1 = str1.Split(new char[2]{'-','_'});

            //*******************【SubString】**********************
            string str2 = "yyyy-MM-dd";
            int startPos = 2;
            int strLength = 4;
            string subString = str2.Substring(startPos, strLength); // subString:"yy-M"

            string subString1 = str2.Substring(startPos); //subString2:"yy-MM-dd"

            //*******************【Replace】**********************
            string str3 = "yyyy-MM-dd";
            string strReplace = str3.Replace("MM", "mm"); //strReplace: "yyyy-mm-dd"

            string strReplace1 = str3.Replace("MM", ""); //strReplace1:"yyyy--dd"

            string strReplace2 = str3.Replace("MM", " "); //strReplace2:"yyyy- -dd"


            //*******************【Remove】**********************
            string str4 = "yyyy-MM-dd";
            string strRemove = str4.Remove(3); //strRemove:"yyy"

            string strRemove1 = str4.Remove(0, str4.Length - 1); //strRemove1:"d"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值