Example #1
0
        /// <summary>
        /// 比较规则,先比较字符大小
        /// 在比较长度
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int Compare(StringDS s)
        {
            int len = (this.GetLength() <= s.GetLength()) ? this.GetLength() : s.GetLength();
            int i = 0;
            for (i = 0; i < len; i++)
            {
                if (this[i] != s[i])
                {
                    break;
                }
            }//for

            if (i < len)
            {
                if (this[i] < s[i])
                {
                    return -1;
                }
                else if (this[i] > s[i])
                {
                    return 1;
                }
            }
            else if (this.GetLength() == s.GetLength())
            {
                return 0;
            }
            else if (this.GetLength() < s.GetLength())
            {
                return -1;
            }

            return 1;
        }
Example #2
0
 public StringDS(StringDS s)
 {
 }
Example #3
0
        /// <summary>
        /// 获取索引从0开始的len个字符串
        /// </summary>
        /// <param name="idx">索引从0开始</param>
        /// <param name="len"></param>
        /// <returns></returns>
        public StringDS SubString(int idx, int len)
        {
            if (idx < 0 || idx > this.GetLength() - 1)
            {
                throw new IndexOutOfRangeException("索引超出范围。");
            }//fun

            if (len < 0 || len > this.GetLength() - idx)
            {
                throw new IndexOutOfRangeException("字串长度超出范围。");
            }

            StringDS s = new StringDS(len);

            for (int i = 0; i < len; i++)
            {
                s[i]=this [idx +i];
            }//for

            return s;
        }
Example #4
0
        /// <summary>
        /// 在索引后插入字符串
        /// </summary>
        /// <param name="idx">从0开始</param>
        /// <param name="s"></param>
        /// <returns></returns>
        public StringDS Insert(int idx, StringDS s)
        {
            if (idx < 0 || idx > this.GetLength() - 1)
            {
                throw new IndexOutOfRangeException("索引超出范围。");
            }

            int len = s.GetLength();
            int len2 = this.GetLength() + len;
            StringDS s1 = new StringDS( len2);

            for (int i = 0; i <= idx; i++)
            {
                s1[i] = this[i];
            }//for

            for (int i = idx + 1; i < idx +len ; i++)
            {
                s1[i] = s[i - idx-1];
            }//

            for (int i = idx + len; i < len2; i++)
            {
                s1[i] = this[i - len+1];
            }

            return s1;
        }
Example #5
0
 /// <summary>
 /// 串定位
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public int IndexOf(StringDS s)
 {
     return 0;
 }
Example #6
0
        /// <summary>
        /// 连接串,将两个串合并成一个新串返回
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public StringDS Concat(StringDS s)
        {
            StringDS s1 = new StringDS(this.GetLength() + s.GetLength());

            for (int i = 0; i < this.GetLength(); i++)
            {
                s1[i] = this[i];
            }
            for (int j = 0; j < s.GetLength(); j++)
            {
                s1[this.GetLength() + j] = s[j];
            }//

            return s1;
        }