Advertisement
sergezhu

Untitled

Apr 30th, 2023
722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task14
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.         bool canExit = false;
  13.  
  14.         while ( canExit == false )
  15.         {
  16.             Console.Clear();
  17.             Console.WriteLine( $"Input name" );
  18.             string name = Console.ReadLine();
  19.             int nameWidth = name.Length;
  20.  
  21.             Console.Write( $"Input border char: " );
  22.             char borderChar = Console.ReadKey().KeyChar;
  23.  
  24.             int borderThickness = 1;
  25.             int borderLeftThickness = borderThickness;
  26.             int borderRightThickness = borderThickness;
  27.             int borderWidth = borderLeftThickness + nameWidth + borderRightThickness;
  28.             int borderHeight = 3;
  29.             int nameRowIndex = 1;
  30.  
  31.             Console.WriteLine();
  32.            
  33.             string borderedName = string.Empty;
  34.            
  35.             for ( int rowIndex = 0; rowIndex < borderHeight; rowIndex++ )
  36.             {
  37.                 string line;
  38.    
  39.                 if ( rowIndex == nameRowIndex )
  40.                 {
  41.                     string borderPart = new string( borderChar, borderThickness );
  42.                     line = $"{borderPart}{name}{borderPart}";
  43.                 }
  44.                 else
  45.                 {
  46.                     line = new string( borderChar, borderWidth );
  47.                 }
  48.  
  49.                 borderedName = $"{borderedName}{line}\n";
  50.             }
  51.  
  52.             Console.WriteLine( borderedName );
  53.  
  54.             string properlyExitAnswer = "n";
  55.             Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
  56.             string continueAnswer = Console.ReadLine();
  57.  
  58.             canExit = string.Equals( continueAnswer, properlyExitAnswer );
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement