using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 字符串 { class stringDG { public char[] date;//字符串本质上是一个数组,是一个字符型数组 /// <summary> /// 给类添加一个构造函数,在创建对象时可以对对象进行赋值,这个构造函数可以把字符数组转化成字符串 /// </summary> /// <param name="array"></param> public stringDG(char[] array) { date = new char[array.Length];//确定字符串数组的长度 for (int i = 0; i < array.Length; i++) { date[i] = array[i]; } } /// <summary> /// stringDg类的构造函数,在创建对象时,把字符串内容传入类中 /// </summary> /// <param name="array"></param> public stringDG(stringDG array) { date = new char[array.GetLength]; for (int i = 0; i < array.GetLength; i++) { date[i] = array.date[i]; } } //空构造函数 public stringDG() { } /// <summary> /// 获取字符串的长度 /// </summary> /// <param name="array"></param> /// <returns></returns> public int GetLength { get { return date.Length; } } /// <summary> /// 截取字符串 /// </summary> /// <param name="index"></param> /// <param name="length"></param> /// <returns></returns> public stringDG SubString(int index,int length) { char[] str = new char[length]; int temp = 0; for (int i = index; i < index+length; i++) { str[temp] = date[i]; } return new stringDG(str); } /// <summary> /// 通过下标获取字符 /// </summary> /// <param name="index"></param> /// <returns></returns> public char GetValue(int index) { return date[index]; } } }