public bool Equals(MyString value) { if (MyString.Compare(this, value) == 0) { return(true); } return(false); }
public static void Main(string[] args) { string stringstr1; Console.Write($"Welcom to MyString Test Application{Environment.NewLine}Enter string line: "); stringstr1 = Console.ReadLine(); MyString mystr1 = new MyString(stringstr1); Console.WriteLine($"MyString from string line is: {mystr1}{Environment.NewLine}It's length is {mystr1.Length}{Environment.NewLine}"); Console.Write("Enter another two MyString lines to compare them. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); MyString mystr2 = new MyString(Console.ReadLine()); switch (MyString.Compare(mystr1, mystr2)) { case 1: Console.WriteLine("First one is bigger"); break; case -1: Console.WriteLine("Second one is bigger"); break; case 0: Console.WriteLine("They are the same"); break; } Console.WriteLine(); Console.Write("Enter another two MyString lines to concatenate them. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); mystr2 = new MyString(Console.ReadLine()); Console.WriteLine($"The concatenation is: {MyString.Concat(mystr1, mystr2)}"); Console.WriteLine(); Console.Write("Enter another two MyString lines to find out, if they are equal. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); mystr2 = new MyString(Console.ReadLine()); if (mystr1.Equals(mystr2)) { Console.WriteLine("They are equal"); } else { Console.WriteLine("They are not equal"); } Console.WriteLine(); Console.Write("Enter another two MyString lines to find if the first contains second. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); mystr2 = new MyString(Console.ReadLine()); if (mystr1.Contains(mystr2)) { Console.WriteLine("It does"); } else { Console.WriteLine("It doesn't"); } Console.WriteLine(); Console.Write("Enter another two MyString lines to find if the first starts with second. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); mystr2 = new MyString(Console.ReadLine()); if (mystr1.StartsWith(mystr2)) { Console.WriteLine("It does"); } else { Console.WriteLine("It doesn't"); } Console.WriteLine(); Console.Write("Enter another two MyString lines to find if the first ends with second. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); mystr2 = new MyString(Console.ReadLine()); if (mystr1.EndsWith(mystr2)) { Console.WriteLine("It does"); } else { Console.WriteLine("It doesn't"); } Console.WriteLine(); Console.Write("Enter MyString to find the index of a sybmbol. MyString: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Sybmbol: "); char symbol = char.Parse(Console.ReadLine()); if (mystr1.IndexOf(symbol) == -1) { Console.WriteLine("There is no such symbol"); } else { Console.WriteLine(mystr1.IndexOf(symbol)); } Console.WriteLine(); Console.Write("Enter MyString to find the last index of a sybmbol. MyString: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Sybmbol: "); symbol = char.Parse(Console.ReadLine()); if (mystr1.LastIndexOf(symbol) == -1) { Console.WriteLine("There is no such symbol"); } else { Console.WriteLine(mystr1.LastIndexOf(symbol)); } Console.WriteLine(); Console.Write("Enter MyString to find the first index of any symbol in char array. MyString: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Sybmbols: "); char[] symbols = Console.ReadLine().ToCharArray(); if (mystr1.IndexOfAny(symbols) == -1) { Console.WriteLine("There is no such symbols"); } else { Console.WriteLine(mystr1.IndexOfAny(symbols)); } Console.WriteLine(); Console.Write("Enter MyString to find the last index of any symbol in char array. MyString: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Sybmbols: "); symbols = Console.ReadLine().ToCharArray(); if (mystr1.LastIndexOfAny(symbols) == -1) { Console.WriteLine("There is no such symbols"); } else { Console.WriteLine(mystr1.LastIndexOfAny(symbols)); } Console.WriteLine(); Console.Write("Enter MyString to make it to upper: "); mystr1 = new MyString(Console.ReadLine()); mystr1.ToUpper(); Console.WriteLine($"The result is: {mystr1}"); Console.WriteLine(); Console.Write("Enter MyString to make it to lower: "); mystr1 = new MyString(Console.ReadLine()); mystr1.ToLower(); Console.WriteLine($"The result is: {mystr1}"); Console.WriteLine(); Console.Write("Enter another two MyString lines and position to insert second in the first. First one: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Second one: "); mystr2 = new MyString(Console.ReadLine()); Console.Write("Position: "); int position = int.Parse(Console.ReadLine()); Console.WriteLine($"The result is: {mystr1.Insert(position, mystr2)}"); Console.WriteLine(); Console.Write("Enter another MyString line and start and end positions to remove elements. MyString: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Start: "); position = int.Parse(Console.ReadLine()); Console.Write("End: "); int position1 = int.Parse(Console.ReadLine()); Console.WriteLine($"The result is: {mystr1.Remove(position, position1)}"); Console.WriteLine(); Console.Write("Enter another MyString line and start and end positions to generate SubMyString. MyString: "); mystr1 = new MyString(Console.ReadLine()); Console.Write("Start: "); position = int.Parse(Console.ReadLine()); Console.Write("End: "); position1 = int.Parse(Console.ReadLine()); Console.WriteLine($"The result is: {mystr1.SubMyString(position, position1)}"); Console.WriteLine(); }
public static void Main(string[] args) { string s1 = "First string"; string s2 = "Second string"; string s3 = "First string"; string s4 = "rst stri"; string arrow = " => "; char l = 'l'; char dot = '.'; char[] charArray = s3.ToCharArray(); MyString myStr1 = new MyString(s1); MyString myStr2 = new MyString(s2); MyString myStr3 = new MyString(charArray); int comp1 = myStr1.Compare(myStr2); int comp2 = myStr1.Compare(s3); bool b1 = myStr1.Contains(l); bool b2 = myStr1.Contains(s4); bool b3 = myStr1.Contains(myStr3); MyString myStr4 = myStr1.Concat('.'); MyString myStr5 = myStr1.Concat(" => "); MyString myStr6 = myStr1.Concat(myStr2); MyString myStr7 = myStr1 + myStr3; { Console.WriteLine("Some work with class \"MyString\""); Console.WriteLine(Environment.NewLine); Console.WriteLine($"{nameof(myStr1)} = {myStr1}"); Console.WriteLine($"{nameof(myStr2)} = {myStr2}"); Console.WriteLine($"{nameof(myStr3)} = {myStr3}"); Console.WriteLine(Environment.NewLine); Console.WriteLine($"{nameof(myStr1)} is bigger (1), smaller (2) or equal (0) to {nameof(myStr2)}: {comp1}"); Console.WriteLine($"{nameof(myStr1)} is bigger (1), smaller (2) or equal (0) to {nameof(s3)}: {comp2}"); Console.WriteLine(Environment.NewLine); Console.WriteLine($"{nameof(myStr1)} contains '{l}': {b1}"); Console.WriteLine($"{nameof(myStr1)} contains \"{s4}\": {b2}"); Console.WriteLine($"{nameof(myStr1)} contains {nameof(myStr3)}: {b3}"); Console.WriteLine(Environment.NewLine); Console.WriteLine("Sum of MyStrings with Concat():"); Console.WriteLine($"{nameof(myStr1)} and '{dot}': {myStr4}"); Console.WriteLine($"{nameof(myStr1)} and \"{arrow}\": {myStr5}"); Console.WriteLine($"{nameof(myStr1)} and {nameof(myStr2)}: {myStr6}"); Console.WriteLine(Environment.NewLine); Console.WriteLine("Sum of MyStrings with overloaded operator '+':"); Console.WriteLine($"{nameof(myStr1)} + {nameof(myStr3)}: {myStr7}"); Console.WriteLine(Environment.NewLine); Console.WriteLine($"{nameof(myStr1)}[6] = {myStr1[6]}"); } char[] charArray2 = myStr1; StringBuilder sb = myStr1; string myStrAsString = (string)myStr1; MyString myStr8 = (MyString)"Test string"; MyString mySstr9 = (MyString)charArray; }