Beispiel #1
0
 public void Concat(SequencedString s2)
 {
     for (int i = 0; i < s2.Length; i++)
     {
         this.Concat(s2[i]);
     }
 }
Beispiel #2
0
        public int IndexOf(SequencedString sub)
        {
            int  i = 0, j;
            bool found = false;

            if (sub.Length == 0)
            {
                return(0);
            }
            while (i < count)
            {
                j = 0;
                while (j < sub.Length && this.items[i + j] == sub[j])
                {
                    j++;
                }
                if (j == sub.Length)
                {
                    found = true;
                    break;
                }
                else
                {
                    i++;
                }
            }
            if (found)
            {
                return(i);
            }
            else
            {
                return(-1);
            }
        }
Beispiel #3
0
        public static SequencedString operator +(SequencedString s1, SequencedString s2)
        {
            SequencedString newstr = new SequencedString(s1.Length + s2.Length);

            newstr.Concat(s1);
            newstr.Concat(s2);
            return(newstr);
        }
Beispiel #4
0
        public SequencedString Reverse()
        {
            int             i;
            SequencedString newstr = new SequencedString(items.Length);

            for (i = this.Length - 1; i >= 0; i--)
            {
                newstr.Concat(this.items[i]);
            }
            return(newstr);
        }
Beispiel #5
0
        public SequencedString Remove(int i, int n)
        {
            SequencedString sub1, sub2, sub3;

            sub1 = this.Substring(0, i);
            sub2 = this.Substring(i, n);
            sub3 = this.Substring(i + n, this.Length - i - n);
            SequencedString newstr = new SequencedString(items.Length);

            newstr.Concat(sub1);
            newstr.Concat(sub3);
            return(newstr);
        }
Beispiel #6
0
        public SequencedString Insert(int i, char c)
        {
            SequencedString sub1, sub2;

            sub1 = this.Substring(0, i);
            sub2 = this.Substring(i, this.Length - i);
            SequencedString newstr = new SequencedString(items.Length + 8);

            newstr.Concat(sub1);
            newstr.Concat(c);
            newstr.Concat(sub2);
            return(newstr);
        }
Beispiel #7
0
        public SequencedString Replace(SequencedString oldsub, SequencedString newsub)
        {
            int             i, n;
            SequencedString sub1, sub3;
            SequencedString newstr = new SequencedString(items.Length + newsub.Length);

            i = this.IndexOf(oldsub);
            if (i != -1)
            {
                sub1 = this.Substring(0, i);
                n    = oldsub.Length;
                sub3 = this.Substring(i + n, this.Length - i - n);
                newstr.Concat(sub1);
                newstr.Concat(newstr);
                newstr.Concat(sub3);
            }
            return(newstr);
        }
Beispiel #8
0
        public SequencedString Substring(int i, int n)
        {
            int j = 0;

            if ((i >= 0 && n >= 0) && (i + n <= this.Length))
            {
                SequencedString sub = new SequencedString(n * 2);
                while (j < n)
                {
                    sub.items[j] = this.items[i + j];
                    j++;
                }
                sub.count = j;
                return(sub);
            }
            else
            {
                return(null);
            }
        }