美文网首页
C# 字符串方法和属性的演示源码

C# 字符串方法和属性的演示源码

作者: code男人 | 来源:发表于2018-12-20 09:52 被阅读0次

    在内容期间,将做工程过程中比较常用的内容段备份一下,下面的内容段是关于C# 字符串方法和属性的演示的内容,应该是对码农们有好处。

    using System;

    class StringMethods

    {

      static void Main()

      {

          char[] characterArray;

          int position;

          string result, string1;

          string1 = "The education of Cissy!";

          characterArray = new char[30];

          result = "string = "" + string1 + """;

          result += "nstring length = " + string1.Length;

          position = string1.IndexOf ("e");

          result += "nstring contains an 'e' at index: "

            + position;

          position = string1.IndexOf ("e", position + 1);

          result += "nstring contains a second 'e' at index: "

            + position;

          if (string1.Contains ("Cissy"))

          result += "nstring contains 'Cissy' --> "

            + string1.Contains ("Cissy");

          position = string1.IndexOf("Cissy");

          result += "n'Cissy' starts at index: "

            + position;

          result += "nlower case string: ""

            + string1.ToLower() + """;

          result += "nupper case string: ""

            + string1.ToUpper() + """;

          result += "nreverse string: "";

          for (int i = string1.Length - 1; i >= 0; i--)

          {

            result += string1[i];

          }

          result += ""nreplace 'educ' with 'matur': ";

          result += """ + string1.Replace ("educ", "matur") + """;

          string1.CopyTo (0, characterArray, 0, 6);

          result += "nFirst 6 characters of array contain: "";

          for (int i = 0; i < 6; i++)

          {

            result += characterArray[i];

          }

          Console.WriteLine (result +

            ""nn(Press "Enter" to exit.)");

          Console.Read();

      }

    }

    相关文章

      网友评论

          本文标题:C# 字符串方法和属性的演示源码

          本文链接:https://www.haomeiwen.com/subject/ngbekqtx.html