static void Main(string[] args) { Console.InputEncoding = Encoding.Unicode; Console.OutputEncoding = Encoding.Unicode; MyString str1 = new MyString(); MyString str2 = new MyString("Строка1"); MyString str3 = new MyString("Строка2"); str1 = "Строка"; str2 = str2 + str3; Console.WriteLine("Исходные строки:"); Console.WriteLine("str1 = {0}", str1.ToString()); Console.WriteLine("str2 = {0}", str2.ToString()); Console.WriteLine("str3 = {0}", str3.ToString()); Console.WriteLine("\nТиповые операции класса MyString:"); Console.WriteLine("str2.Contains('к') = {0}", str3.Contains('к')); Console.WriteLine("str2.EndWith('2') = {0}", str3.EndWith('2')); Console.WriteLine("str3.IndexOf('р') = {0}", str3.IndexOf('р')); Console.WriteLine("str1.Insert(0,\"Новая \") = {0}", str1.Insert(0, "Новая ")); Console.WriteLine("str1.LastIndexOf('а') = {0}", str1.LastIndexOf('а')); Console.WriteLine("str1.Length = {0}", str1.Length); Console.WriteLine("str2.Remove(3) = {0}", str2.Remove(3)); Console.WriteLine("str3.Remove(2, 2) = {0}", str3.Remove(2, 2)); Console.WriteLine("str1.Replace('а', 'б') = {0}", str1.Replace('а', 'б')); Console.WriteLine("str1.StartWith('б') = {0}", str1.StartWith('б')); Console.WriteLine("str1.Substring(4) = {0}", str1.Substring(4)); Console.WriteLine("str1.Substring(1, 3) = {0}", str1.Substring(1, 3)); Console.WriteLine("str1.ToLower() = {0}", str1.ToLower()); Console.WriteLine("str2.ToUpper() = {0}", str2.ToUpper()); Console.ReadKey(); }
public static void Main(string[] args) { // WARNING очень жуткая демонстрация ConsoleKeyInfo cki; do { Console.WriteLine("Enter first string:"); var first = new MyString(Console.ReadLine().ToCharArray()); Console.WriteLine("\t length: {0}", first.Length); Console.WriteLine("\nEnter second string:"); var second = new MyString(Console.ReadLine().ToCharArray()); Console.WriteLine("\t length: {0}", second.Length); MyString newString = first + second; Console.WriteLine("\nJoin two lines: {0}", newString.ToString()); Console.WriteLine("\t length: {0}", newString.Length); newString = newString.Trim(); Console.WriteLine("\nDelite separator from the beginning and end: {0}", newString.ToString()); Console.WriteLine("\t length: {0}", newString.Length); char symbolOld = 'o'; Console.WriteLine("\nFirst occurrence of a symbol '{0}' in a string \"{1}\": {2}", symbolOld, newString.ToString(), newString.IndexOf(symbolOld)); char symbolNew = 'n'; var newString1 = newString.Replace(symbolNew, symbolOld); Console.WriteLine( "Replace the symbol '{0}' -> '{1}' in string \"{2}\": {3}", symbolOld, symbolNew, newString, newString1); int position = 0; string addStr = "add substring"; var newString2 = newString.Insert(addStr, position); Console.WriteLine("\nAdd a substring \"{0}\" in string \"{1}\" from the position '{2}': {3}", addStr, newString.ToString(), position, newString2.ToString()); var newString3 = newString.Split(); Console.WriteLine("\nSplit a string \"{0}\":", newString.ToString()); foreach (var e in newString3) { Console.WriteLine("\t\"{0}\",", e.ToString()); } Console.WriteLine("\nString to lower: {0}", newString.ToLower().ToString()); Console.WriteLine("String to lower: {0}", newString.ToUpper().ToString()); Console.WriteLine("Press the Escape (Esc) key to quit:"); cki = Console.ReadKey(); }while (cki.Key != ConsoleKey.Escape); }
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(); }
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(); }