static void Main(string[] args) { Console.WriteLine("My string"); Console.Write("Введите первую строчку: "); MyString firstMyString = new MyString(Console.ReadLine().ToCharArray()); Console.WriteLine(firstMyString.ToMyString()); Console.Write("Введите вторую строчку: "); MyString secondMyString = new MyString(Console.ReadLine().ToCharArray()); MyString thirdMyString = firstMyString - secondMyString; Console.Write("Третья строка = 1-я - 2-я: "); Console.WriteLine(thirdMyString.ToMyString()); Console.ReadLine(); }
public static MyString operator +(MyString str1, MyString str2) { char[] s1 = str1.StrVal; char[] s2 = str2.StrVal; char[] s = new char[s1.Length + s2.Length]; for (var i = 0; i < s1.Length; i++) { s[i] = s1[i]; } for (var i = 0; i < s2.Length; i++) { s[s1.Length + i] = s2[i]; } var newstr = new MyString(s); return(newstr); }
public static void Main(string[] args) { Console.Write("Enter string 1: "); char[] str1 = Console.ReadLine().ToCharArray(); Console.Write("Enter string 2: "); char[] str2 = Console.ReadLine().ToCharArray(); var mystr1 = new MyString(str1); var mystr2 = new MyString(str2); var mystr3 = mystr1 + mystr2; Console.Write("\noperator +: "); mystr3.Write(); // mystr1.ToUpper(mystr1); mystr1.Insert(3, mystr2.StrVal); Console.Write("\nInsert: "); mystr1.Write(); }
public static void Main(string[] args) { MyString str = new MyString(); string line = "saSAD sadsdsad123sa2341sadSDWsdsf"; Console.WriteLine("String to char array:\nString = {0}\nChar array: ", line); foreach (var chars in str.ToCharArray(line)) { Console.Write("{0} ", chars); } Console.WriteLine("\n\nString to upper:\nString = {0}\nTo upper = {1}", line, str.ToUpper(line)); Console.WriteLine("\nString to lower:\nString = {0}\nTo lower = {1}", line, str.ToLower(line)); Console.WriteLine("\nString remove:\nString = {0}\nRemove from 4 to 13 char = {1}", line, str.Remove(line, 4, 9)); Console.WriteLine("\nString replace:\nString = {0}\nReplace 'a' to 'Z' = {1}", line, str.Replace(line, 'a', 'Z')); Console.ReadKey(); }
public static void Main(string[] args) { WriteLine("Enter string"); MyString str = new MyString(ReadLine().ToCharArray()); WriteLine("ToUpper"); WriteLine(str.ToUpper()); WriteLine("ToLower"); WriteLine(str.ToLower()); WriteLine(@"Contains 'a'"); WriteLine(str.Contains('a')); WriteLine(@"First index of 'a'"); WriteLine(str.FirstIndexOf('a')); WriteLine(@"Last index of 'a'"); WriteLine(str.LastIndexOf('a')); WriteLine("substring(3,6)"); WriteLine(str.Substring(3, 6)); WriteLine(@"replace('a','b')"); WriteLine(str.Replace('a', 'b')); MyString[] split = new MyString[10]; WriteLine("split"); split = str.Split(); for (int i = 0; i < split.Length; i++) { WriteLine(split[i]); } ReadKey(); }
private static void Main(string[] args) { Console.InputEncoding = Encoding.Unicode; Console.OutputEncoding = Encoding.Unicode; MyString str = new MyString(" new"); ShowString("Начальное состояние", str.ToString()); str.Insert(6, new MyString("Str ")); ShowString("Вызов Insert(0,\'Str \')", str.ToString()); str.Remove(3, 3); ShowString("Вызов Remove(3,3)", str.ToString()); str.Trim(); ShowString("Вызов Trim()", str.ToString()); str.ToLower(); ShowString("Вызов ToLower()", str.ToString()); str.ToUpper(); ShowString("Вызов ToUpper()", str.ToString()); str.Insert(0, new MyString("abcdeabcdeabcde")); ShowString("Вызов Insert", str.ToString()); str.Replace('a', 'K'); ShowString("Вызов Replace(\'a\', \'K\')", str.ToString()); ShowString("Обращение к str[5]", str[5].ToString()); ShowString("Вызов IndexOf(\'K\')", str.IndexOf('K').ToString()); ShowString("Вызов LastIndexOf(\'K\')", str.LastIndexOf('K').ToString()); ShowString("Вызов Contains(\'T\')", str.Contains('T').ToString()); Console.ReadKey(); }