//String 字符串的常见操作
        public static void Fun1()
        {
            string MyStr = " Hello World! ";

            //length长度属性
            Console.WriteLine(MyStr.Length);

            //Substring()截取
            Console.WriteLine(MyStr.Substring(, ));

            //ToCharArray()转换为字符数组
            char[] charr = MyStr.ToCharArray();

            //ToUpper()转换大写
            string UpperStr = MyStr.ToUpper();
            Console.WriteLine("转换为大写:" + UpperStr + "\n");

            //ToLower()转换小写
            Console.WriteLine("转换为小写:" + MyStr.ToLower());

            //TrimStart() and TrimEnd() 去掉字符左右边的空格 TrimStart--去掉左边
            string LefStr = MyStr.TrimStart();
            string RigStr = MyStr.TrimEnd();

            Console.WriteLine("左边 " + LefStr + "\n" + "右边 " + RigStr + "\n");

            //Replace()替换字符
            string ReplaceStr = MyStr.Replace('W', 'M');
            Console.WriteLine("替换字符 " + ReplaceStr + "\n");

            //Concat()连接字符
            string concatStr = string.Concat(MyStr, "asas", "asasa");
            Console.WriteLine("连接字符 " + concatStr + "\n");

            //IsNullOrEmpty()判断空值
            bool NullorEmpty = string.IsNullOrEmpty(MyStr);
            Console.WriteLine("判断空值 " + NullorEmpty.ToString() + "\n");

            //StartsWith()开头
            Console.WriteLine(MyStr.StartsWith(" ") == true);

            //EndsWith()结尾
            bool endwith = MyStr.EndsWith(" ");
            Console.WriteLine("结尾 " + endwith.ToString() + "\n");

            //IndexOf() and LastIndexOf()字符串的位置
            string strLocation = "123abc4c56efd";
            Console.WriteLine(') + "\n");
            Console.WriteLine("LastIndexOf:" + strLocation.LastIndexOf('c') + "\n");

            //插入字符
            Console.WriteLine(MyStr.Insert(, "W"));

            //MyStr.PadLeft();MyStr.PadRight()

            //Remove()移除
            Console.WriteLine(, ) + "\n");

            //Format()格式化
            );
            Console.WriteLine(str);

            //Compare()和CompareTo() 比较方法
            string strA = "File.exe";
            ";

            int numA = string.Compare(strA, strB);
            Console.WriteLine("Compare: " + numA.ToString() + "\n");

            int numB = strA.CompareTo(strB);
            Console.WriteLine("CompareTo: " + numB.ToString());

            //比较两个指定的 System.String 对象。
            // 返回结果:
            // 一个 32 位有符号整数,指示两个比较数之间的词法关系。
            //值条件小于零 strA 小于 strB。 零strA 等于 strB。 大于零 strA大于 strB。 

        }

常用的就这些吧,有好的话我在补上!!!

最新文章

  1. 使用python处理子域名爆破工具subdomainsbrute结果txt
  2. Fedora 23安装 NS2 (network simulator 2)
  3. C#基础-可访问性-public、ptotected、protected internal、internal、private
  4. 14周事情总结-机器人-大数据hadoop
  5. SOA和微服务
  6. 弹出层easydialog-v2.0
  7. Maven简介(一)
  8. 安装mysql到服务器的linux环境下
  9. genymotion的安装及运行
  10. Android中资源的引用
  11. Vue 组件&组件之间的通信 之 使用slot分发内容
  12. Flutter 布局控件完结篇
  13. oracle日志归档空间清理
  14. abc高级bash shell编程
  15. 软件包管理:rpm命令管理-包命名与依赖性
  16. 知乎回答:每日完成任务用于打卡的APP
  17. Linux之静态库与动态库20160706
  18. mysql 查询条件
  19. Java面向对象作业-用接口方式测试向下转型
  20. 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-通知(Advice)API

热门文章

  1. web开发模式小结:页面乱码和跳转
  2. redis在Windows下以后台服务一键搭建集群(单机--伪集群)
  3. 更改placeholder样式
  4. Python Visual Studio 2015
  5. org.hibernate.HibernateException: Unable to get the defa
  6. IOS UITabBarController(控制器)的子控制器
  7. Linux I/O调度
  8. UVA 1213 - Sum of Different Primes(递推)
  9. kubernetes-ingress(十)
  10. 漫谈Ajax在.Net中的使用