Exemple #1
0
        public static int FindMyString(MyString text1, MyString text2)
        {
            if (text1.MyLength() < text2.MyLength())
            {
                return(-1);
            }

            int len = text1.MyLength() - text2.MyLength();
            int j   = 0;

            for (int i = 0; i < text2.MyLength(); i++)
            {
                while (!(text2.Mystring[i] == text1.Mystring[i + j]) && (j < len))
                {
                    j++;
                }

                if (!(text2.Mystring[i] == text1.Mystring[i + j]))
                {
                    return(-1);
                }
            }

            return(j);
        }
Exemple #2
0
 public static int CompareMyString(MyString text1, MyString text2)
 {
     if (text1.MyLength() > text2.MyLength())
     {
         return(1);
     }
     else
     {
         if (text1.MyLength() < text2.MyLength())
         {
             return(-1);
         }
         else
         {
             return(0);
         }
     }
 }
Exemple #3
0
        public static string MyToString(MyString text)
        {
            string result = string.Empty;

            for (int i = 0; i < text.MyLength(); i++)
            {
                result += text.Mystring[i];
            }

            return(result);
        }
Exemple #4
0
        public static char[] MyConcat(MyString text1, MyString text2)
        {
            int len = text1.MyLength() + text2.MyLength();

            char[] concat = new char[len];

            for (int i = 0; i < text1.MyLength(); i++)
            {
                concat[i] = text1.Mystring[i];
            }

            len = text1.MyLength();

            for (int i = 0; i < text2.MyLength(); i++)
            {
                concat[i + len] = text2.Mystring[i];
            }

            return(concat);
        }
        public static void Main(string[] args)
        {
            string   text1 = " sample1 ";
            string   text2 = "sample";
            MyString p     = new MyString(text1);
            MyString r     = new MyString(text2);

            char[] s = MyString.MyConcat(p, r);
            Console.WriteLine(s);

            int i = 2;

            i = MyString.CompareMyString(p, r);
            Console.WriteLine(i);
            Console.WriteLine(p.MyLength());
            Console.WriteLine(MyString.MyToString(p));

            i = MyString.FindMyString(p, r);
            Console.WriteLine(i);
        }