Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace console
- {
- class Program
- {
- void strs1(ref string str1)
- {
- if (str1 != "")
- {
- Console.WriteLine("Текст 1 строки:{0}", str1);
- Console.Write("Хотите изменить 1 строку y/n :");
- if (Console.ReadLine() == "y")
- str1 = Console.ReadLine();
- }
- else
- {
- Console.Write("Введите 1 строку с которой будите работать:");
- str1 = Console.ReadLine();
- }
- }
- void strs2(ref string str2)
- {
- if (str2 != "")
- {
- Console.WriteLine("Текст 2 строки:{0}", str2);
- Console.Write("Хотите изменить 2 строку y/n :");
- if (Console.ReadLine() == "y")
- str2 = Console.ReadLine();
- }
- else
- {
- Console.Write("Введите 2 строку с которой будите работать:");
- str2 = Console.ReadLine();
- }
- }
- static void Main(string[] args)
- {
- Program fun = new Program();
- string str1 = "", str2 = "", str3 = "", str4 = "", met = "";
- start:
- Console.SetCursorPosition(0, 0);
- Console.Clear();
- Console.WriteLine("===========================\nВыбирите метод ред. строки:\n1.Ass(Об’єднання рядків)\n2.Ins(Вставлення рядків)\n3.Rep(Заміна рядків;)\n4.Del(Вилучення рядків)\n5.Com(Порівняння двох рядків)\n6.Compary(Порівняння символів із двох рядків, які знаходяться на певних місцях)\n7.Ind(Визначення індексу першого входження заданого рядка в інший)\n0.Exit(Выход)");
- met = Console.ReadLine();
- switch (met)
- {
- case "Ass":
- case "ass":
- case "1":
- fun.strs1(ref str1);
- fun.strs2(ref str2);
- Console.WriteLine(String.Concat(str1, str2));
- break;
- case "Ins":
- case "ins":
- case "2":
- fun.strs1(ref str1);
- fun.strs2(ref str2);
- Console.Write("Введите слово(символ) из 1 строки перед которым хотите вставить 2 сроку:");
- str3 = Console.ReadLine();
- str2 = String.Concat(str2, " ");
- Console.WriteLine(str1.Insert(str1.IndexOf(str3), str2));
- break;
- case "Rep":
- case "rep":
- case "3":
- fun.strs1(ref str1);
- Console.Write("Введите слово(символ) которое хотите заменить из 1 строки:");
- str3 = Console.ReadLine();
- Console.Write("Введите слово(символ) на которое хотите заменить слово(символ):");
- str4 = Console.ReadLine();
- Console.WriteLine(str1.Replace(str3, str4));
- break;
- case "Del":
- case "del":
- case "4":
- fun.strs1(ref str1);
- Console.Write("Введите слово(часть слова,символ) которое хотите удалить из 1 строки:");
- str3 = Console.ReadLine();
- Console.WriteLine(str3.Length + " " + str1.IndexOf(str3));
- Console.WriteLine(str1.Remove(str1.IndexOf(str3), str3.Length + 1));
- break;
- case "Com":
- case "com":
- case "5":
- fun.strs1(ref str1);
- fun.strs2(ref str2);
- Console.WriteLine("Ответ: " + String.Compare(str1, str2));
- Console.WriteLine("-1 : не равны вообще\n0 : равны по длинне и содержанию\n1: равны только по длинне");
- break;
- case "Compary":
- case "compary":
- case "6":
- fun.strs1(ref str1);
- fun.strs2(ref str2);
- switch (String.Compare(str1, 0, str2, 0, 1))
- {
- case -1:
- case 1:
- Console.WriteLine("Первые символы не равны");
- break;
- default:
- Console.WriteLine("Первые символы равны");
- break;
- }
- break;
- case "Ind":
- case "ind":
- case "7":
- fun.strs1(ref str1);
- fun.strs2(ref str2);
- Console.Write("Введите символ или слово которое хотите найти в 1 строке:");
- str3 = Console.ReadLine();
- Console.WriteLine("Он находиться по индексу: " + str1.IndexOf(str3));
- break;
- default:
- Console.Write("Спасибо за внимание");
- goto exit;
- }
- Console.Write("Нажмите для продолжения...");
- Console.ReadLine();
- goto start;
- exit:
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement