Beispiel #1
0
        static void Main(string[] args)
        {
            char[]    string1 = { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' };
            MojString s       = new MojString(string1);

            MojString[] s1 = s.Split('o');
            for (int i = 0; i < s1.Length; i++)
            {
                s1[i].Print(true);
            }
        }
Beispiel #2
0
        private MojString[] AddStringToArray(MojString[] baseS, MojString s)
        {
            MojString[] newBaseS = new MojString[baseS.Length + 1];
            for (int i = 0; i < baseS.Length; i++)
            {
                newBaseS[i] = baseS[i].Copy();
            }
            newBaseS[newBaseS.Length - 1] = s.Copy();

            return(newBaseS);
        }
Beispiel #3
0
 public void Append(MojString s)
 {
     char[] newStr = new char[GetLength() + s.GetLength()];
     for (int i = 0; i < GetLength(); i++)
     {
         newStr[i] = GetCharAt(i);
     }
     for (int i = GetLength(); i < GetLength() + s.GetLength(); i++)
     {
         newStr[i] = s.GetCharAt(i - GetLength());
     }
     str = newStr;
 }
Beispiel #4
0
 public void Prepend(MojString s)
 {
     char[] newStr = new char[GetLength() + s.GetLength()];
     for (int i = 0; i < s.GetLength(); i++)
     {
         SetCharAt(i, s.GetCharAt(i));
     }
     for (int i = s.GetLength(); i < GetLength() + s.GetLength(); i++)
     {
         SetCharAt(i, GetCharAt(i - s.GetLength()));
     }
     str = newStr;
     //s.Append(this);
 }
Beispiel #5
0
 public MojString Substring(int i, int n)
 {
     if (str != null)
     {
         if (i >= 0 && i + n < GetLength())
         {
             MojString s = new MojString(new char[0]);
             for (int j = i; j <= i + n; j++)
             {
                 s.Add(GetCharAt(j));
             }
             return(s);
         }
     }
     return(new MojString(new char[0]));
 }
Beispiel #6
0
        public MojString[] Split(char c)
        {
            MojString[] s = new MojString[0];

            int begin = 0;

            for (int i = 0; i < GetLength(); i++)
            {
                if (GetCharAt(i) == c)
                {
                    s     = AddStringToArray(s, Substring(begin, i - 1));
                    begin = i + 1;
                }
                else if (i == GetLength() - 1)
                {
                    s = AddStringToArray(s, Substring(begin, i));
                }
            }

            return(s);
        }
Beispiel #7
0
 public void Insert(int i, MojString s)
 {
     char[] newStr = new char[GetLength() + s.GetLength()];
     for (int j = 0; j < GetLength() + s.GetLength(); j++)
     {
         if (j == i)
         {
             for (; j < s.GetLength() + i; j++)
             {
                 newStr[j] = s.GetCharAt(j - i);
             }
             j--;
         }
         else if (j < i)
         {
             newStr[j] = GetCharAt(j);
         }
         else
         {
             newStr[j] = GetCharAt(j - s.GetLength());
         }
     }
     str = newStr;
 }
Beispiel #8
0
        public MojString Copy()
        {
            MojString s = new MojString(str);

            return(s);
        }