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

在内容期间,将做工程过程中比较常用的内容段备份一下,下面的内容段是关于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# 字符串方法和属性的演示源码)