• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

字符串的处理[C#]

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

            //string Str1 = "友情相逢";
            //string Str2 = "用一生爱你";
            //#region char的使用
            //char a = 'a';
            //Console.WriteLine("IsLetter方法判断a是否为字母:{0}", Char.IsLetter(a));
            //Console.WriteLine("IsDigit方法判断a是否为数字:{0}", Char.IsDigit(a));
            //Console.WriteLine("IsLower方法判断a是否为小写字母:{0}", Char.IsLower(a));
            //Console.WriteLine("IsUpper方法判断a是否为大写字母:{0}", Char.IsUpper(a));
            //Console.WriteLine("IsWhiteSpace方法判断a是否为空白:{0}", Char.IsWhiteSpace(a));
            //#endregion

            //#region String类的使用
            //string Str1 = "用一生爱护你!";
            //char Str2 = Str1[1];
            //char Str3 = Str1[2];
            //Console.WriteLine("字符串Str1中第二个字符是:{0}", Str2);
            //Console.WriteLine("字符串Str1中第三个字符是:{0}", Str3);
            //#endregion

            //#region Conpare/CompareTo比较字符串的使用
            //Console.WriteLine(string.Compare(Str1, Str2));
            //Console.WriteLine(string.Compare(Str1, Str1));
            //Console.WriteLine(string.Compare(Str2, Str1));

            //Console.WriteLine(Str1.CompareTo(Str2));

            //Console.WriteLine(string.Equals(Str1,Str2)); //判断两个字符串是否相等
            //#endregion

            //#region ForMat格式化输出字符串
            //string newstr = String.Format("{0},{1}!!!", Str1, Str2); //ForMat格式化字符串
            //Console.WriteLine(newstr);
            //DateTime dt = DateTime.Now;
            //string time1 = string.Format("{0:D}", dt);
            //string time2 = string.Format("{0:T}", dt);
            //string time3 = string.Format("{0:G}", dt);
            //Console.Write(time1);
            //Console.WriteLine(time2);
            //Console.WriteLine(time3);
            //#endregion


            //#region 截取字符串
            //string Str3 = "";
            //Str3 = Str1.Substring(1, 3);
            //Console.WriteLine(Str3);
            //#endregion

            //#region 分割字符串
            //string Str3 = "用!一生,下载";
            //char[] separator = { '!', ',' };
            //String[] splitstrings = new String[20];
            //splitstrings = Str3.Split(separator);
            //for (int i = 0; i <= splitstrings.Length; i++)
            //{
            //    Console.WriteLine("item{0}:{1}", i, splitstrings[i]);
            //}
            //#endregion

            //#region 插入和填充字符串
            //string str3 = "下载";
            //string str4;
            //str4 = str3.Insert(0, "用一生");
            //string str5 = str4.Insert(5, "你");
            //Console.WriteLine(str5);

            //string str6 = "*+_+*";
            //string str7 = str6.PadLeft(6, '(');     //在字符串左侧添加,确保添加后的总字符串为6
            //string str8 = str7.PadRight(7, ')');
            //Console.WriteLine("补充字符串之前" + str6);
            //Console.WriteLine("补充字符串之后" + str8);
            //#endregion

            //#region 删除字符串
            //string str3 = "用一生下载你";
            //string str4 = str3.Remove(3);  //3为所以字符 往后的都删掉
            //Console.WriteLine(str4);

            //string str5 = str3.Remove(0, 3);  //0为索引,3为删除的字符数
            //Console.WriteLine(str5);
            //#endregion

            //#region 字符串的复制
            //string str = "我爱你forever";
            //string Str;
            //Str = String.Copy(str);   //将str复制给Str
            //Console.WriteLine(Str);

            //string str3 = "用一生下载你";
            //char[] str4 = new char[100];
            //str3.CopyTo(1, str4, 0, 4);     //第一个参数是原字符要复制的起始位置,第二个是新字符,第三个是新字符的复制的起始位置,第四个是复制的字符个数
            //Console.WriteLine(str4);
            //#endregion

            //string a = "one world ,one dream";
            //string b = a.Replace(',','*');    // 字符的替换用单引号
            //Console.WriteLine(b);
            //string c = a.Replace("one world","One World");  //字符串替换用双引号
            //Console.WriteLine(c);


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#索引器发布时间:2022-07-10
下一篇:
如何创建C# Closure ?发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap