Advertisement
sergezhu

Untitled

Apr 30th, 2023
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task26
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.         char splitDivider = ' ';
  13.         string lineBreak = "\n";
  14.  
  15.         bool canExit = false;
  16.  
  17.         while ( canExit == false )
  18.         {
  19.             Console.Clear();
  20.  
  21.             Console.WriteLine("Input text:");
  22.             string enteredText = Console.ReadLine();
  23.             string[] words = enteredText.Split( splitDivider, StringSplitOptions.RemoveEmptyEntries );
  24.  
  25.             string displayedWords = string.Empty;
  26.  
  27.             foreach ( var word in words )
  28.                 displayedWords = $"{displayedWords}{word}{lineBreak}";
  29.            
  30.             Console.WriteLine( $"Separated words:\n{displayedWords}" );
  31.  
  32.             string properlyExitAnswer = "n";
  33.             Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
  34.             string continueAnswer = Console.ReadLine();
  35.  
  36.             canExit = string.Equals( continueAnswer, properlyExitAnswer );
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement