This question has already been answered:

tell me what needs to be done so that after performing an action with a string, the program returns to the choice of action?

string str = "Hello guys!"; Console.WriteLine(str); Console.WriteLine("\nWhat we want to do with this string?"); Console.WriteLine("\nInsert - 0; \nRemove - 1; \nReaplace - 2; \nContains - 3; \nExit - 4;\n"); // выбор действия со строкой. int e = Convert.ToInt32(Console.ReadLine()); if (e == 0) { Console.WriteLine("Enter the number of latter: "); // место, в которое нужно вставить символы int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the letter , that we want to insert: "); // символ/ы который/ые вставляем string str1 = Console.ReadLine(); Console.WriteLine(str.Insert(i, "" + str1 + "")); } 

Reported as a duplicate by the participants tym32167 , Denis Bubnov , 0xdb , Jarvis_J , Mr. Black Jun 29 '18 at 12:02 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Why not just put your code in a while? - ThusMad
  • one
    do {...} while (I == 0); ? - NewView
  • 3
    By the way, the word ребята in English will be guys , not like yours. - Bulson
  • @ThusMad, could you explain in more detail how to accomplish my task using a while loop? (Return to the menu for selecting an action with a string)? - Aleksei Grabor

1 answer 1

In your case, the code will be as follows:

  int e; string str = "Hello gues!"; Console.WriteLine(str); do { Console.WriteLine("\nWhat we want to do with this string?"); Console.WriteLine("\nInsert - 0; \nRemove - 1; \nReaplace - 2; \nContains - 3; \nExit - 4;\n"); // выбор действия со строкой. e = Convert.ToInt32(Console.ReadLine()); if (e == 0) { Console.WriteLine("Enter the position of latter: "); // место, в которое нужно вставить символы int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter the letter , that we want to insert: "); // символ/ы который/ые вставляем string str1 = Console.ReadLine(); Console.WriteLine(str.Insert(i, "" + str1 + "")); } } while (e != 4); // т.к 4 у вас условие выхода 
  • and it is possible to write this part of the line somehow, or rather the second parameter ("" + str1 + "") - Console.WriteLine (str.Insert (i, "" + str1 + "")); ? - Aleksei Grabor
  • @AlekseiGrabor can write here str.Insert (i, str1) - Thus Mad