//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. C# DateTime的时区

    C#中可以通过DateTime的Kind属性指定DateTime的时区 DateTimeKind有3个枚举值: Unspecified:未指定为UTC时间或本地时间 Utc: UTC时间 Local: ...

  2. 微软高性能缓存AppFabric(二)使用

    原文链接:http://www.cnblogs.com/Qbit/p/6102614.html 从AppFabric 的安装目录中选择两个dll添加到项目中, 默认安装位置:C:\Program Fi ...

  3. pat甲级1044二分查找

    1044 Shopping in Mars(25 分) Shopping in Mars is quite a different experience. The Mars people pay by ...

  4. 如何处理CloudFoundry应用部署时遇到的254错误

    使用SAP云平台的CloudFoundry部署应用: 在cockpit遇到错误信息:instance: a0abe2b5-7623-4cf1-4c65-0c79, index: 0, exit_des ...

  5. CRM User Status profile中Business Transaction字段的用途

    有朋友问到User Status profile中Business Transaction字段的用途,如下图INPR, FINI所示. 实际上,这个字段作为一个桥梁,连接了User Status和Sy ...

  6. 测试发布(maven-assembly-plugin看好你哦)

    项目改成了maven管理,现场需要用增量补丁包的形式发布代码: 2015/4/21 以前试过用ant打补丁包,现在试试maven能不能做同样的事情: maven-assembly-plugin看着可以 ...

  7. angular2+ form 表单中 input输入框的disabled属性设置无效

    最近项目中遇到一个表单input设置disabled问题,直接赋值angular原生的[disabled]=“isDisabled”无效,浏览器警告信息: 无奈,只能按照控制台提示修改: 问题解决

  8. CUDA直方图实例=CPU+GPU(global)+GPU(shared)

    项目打包下载链接 顺便批判下CSDN上传坑爹现象,好多次都是到了95%或者99%就不动了.我……

  9. python换行

    python中如果一行代码太长,看着不方便时,怎么办? 只需要在需要换行的地方添加上符号 \ 就行了.

  10. caller、callee的用法及区别

    1 :caller 返回一个调用当前函数的引用 如果是由顶层调用的话 则返回null (举个栗子哈 caller给你打电话的人  谁给你打电话了 谁调用了你 很显然是下面a函数的执行 只有在打电话的时 ...