//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。 

        }

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

C#入门篇6-2:字符串操作 string常用的函数的更多相关文章

  1. C#入门篇6-1:字符串操作 char常用的函数

    //char 字符的常见操作 public static void FChar() { //判定字符的类别 char ch1 = 'a';//使用小引号 bool bl = true; bl = ch ...

  2. C#入门篇6-4:字符串操作 string分割字符串效率比较

    //分割字符串效率比较 public static void Fund() { //1.用string.Split方法 //a.字节数组: //625毫秒/百万次 string str1 = &quo ...

  3. C#入门篇6-3:字符串操作 string的ToString() Split()和Copy()方法

    //ToString()方法 public static void OutPut() { //字符型转换 转为字符串 Console.WriteLine(.ToString("n" ...

  4. C#入门篇6-6:字符串操作 StringBiulder string char[]之间的转化

    //StringBiulder string char[]之间的转化 public static void Fun3() { StringBuilder sb = new StringBuilder( ...

  5. C#入门篇6-8:字符串操作 深入研究字符串的内存驻留机制

    //字符串的内存驻留机制 public static void Test() { //当有多个字符串变量包含了同样的字符串实际值时, //CLR可能不会为它们重复地分配内存,而是让它们统统指向同一个字 ...

  6. C#入门篇6-11:字符串操作 查找与替换

    #region 查找与替换 public class C4 { //查找 public static void StrFind() { //目标字符串 string str1 = "~awe ...

  7. C#入门篇6-10:字符串操作 DateTime操作

    #region DateTime操作 public class C3 { //DateTime常用的操作 public static void Fun1() { //格式:2012-8-16 11:2 ...

  8. C#入门篇6-9:字符串操作 不值一提的函数【不看也行】

    // 判断输入的是否全是数字:返回结果:true:全是数字:false:有字幕出现 public static bool Isaccord1(string str) { bool bl = true; ...

  9. C#入门篇6-7:字符串操作 看看字符串的特殊之处 值类型与引用类型的区别

    //看看字符串的特殊之处值类型与引用类型的区别 public static void CompareString(string stra, string strb, int i) { #region ...

随机推荐

  1. jQuery中$(function(){})与(function($){})(jQuery)、$(document).ready(function(){})等的区别讲解

    1.(function($){...})(jQuery); (1).原理:       这实际上是匿名函数,如下: function(arg){...} 这就定义了一个匿名函数,参数为arg:而调用函 ...

  2. IOS防作弊产品技术原理分析

    由于时间和水平有限,本文会存在诸多不足,希望得到您的及时反馈与指正,多谢! 工具环境: iPhone 6.系统版本 10.1.1IDA Pro 7.0 0x00:防作弊产品介绍 1.由于IOS系统的不 ...

  3. Spring Boot 的配置文件application.properties

    Spring Boot 中的application.properties 是一个全局的配置文件,放在src/main/resources 目录下或者类路径的/config下. 作为全局配置文件的app ...

  4. 关闭VAX的拼写检查_解决中文红色警告问题

    菜单VAssistX->Visual Assistant X Options->Advanced->Underlines下 取消“Underline spelling errors  ...

  5. 项目移动后报error LNK1123

    VS20101.解决方案窗口 项目|项目属性|配置属性|清单工具|输入和输出|嵌入清单 “是”改为“否”:2.项目|项目属性|配置属性|连接器|清单文件|嵌入清单 “是”改为“否”:3.对于64位的操 ...

  6. HDU3577 线段树(区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3577 ,普通的线段树区间更新题目,较简单. 相当于一个区间覆盖问题,有一点要注意的就是叶子节点是一个长 ...

  7. hdu-1198 Farm Irrigation---并查集+模拟(附测试数据)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1198 题目大意: 有如上图11种土地块,块中的绿色线条为土地块中修好的水渠,现在一片土地由上述的各种 ...

  8. FreeRTOS_软件定时器

    FreeRTOS 软件定时器 实验 创建2个任务,start_task.timercontrol_task. start_stask:创建timercontrol_task任务:创建周期定时器Auto ...

  9. dn.net/blueheart20/article/details/22080489

    dn.net/blueheart20/article/details/22080489

  10. mantis基本配置及邮件服务器配置

    邮件服务器配置 在c:\php-5.0.3\php.ini文件中查找smtp,将localhost改为你的发件服务器,如SMTP = smtp.163.com   在php.ini文件中查找sendm ...