Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Laba5zad6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Введите длину строки с алфавитом 'abcdefgh1234567?!;': ");
  14.             int lengthOfSymbols = Convert.ToInt32(Console.ReadLine());
  15.             Console.WriteLine("Строка:");
  16.             const string symbols = "abcdefgh1234567?!;";
  17.             var rand = new Random();
  18.             StringBuilder text = new StringBuilder() { Length = lengthOfSymbols };
  19.             for (int i = 0; i < text.Length; i++)
  20.             {  
  21.                 int index = rand.Next(symbols.Length);
  22.                 text[i] = symbols[index];
  23.             }
  24.             Console.WriteLine(text + "\n");
  25.             for (int i = 0; i < text.Length; i++)
  26.             {
  27.                 if (text[i] == ';')
  28.                 {
  29.                     text[i] = '_';
  30.                 }
  31.             }
  32.             Console.WriteLine("Строка с заменой ';' на '_':");
  33.             Console.WriteLine(text);
  34.             Console.ReadKey();
  35.         }
  36.      
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement