Advertisement
Bob103

C#_String(II-5)

Oct 27th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ConsoleApplication1
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string str;
  11.             string result;
  12.             Console.WriteLine("Напишите строку ");
  13.             str = Console.ReadLine();
  14.             if (str.Length % 2 != 0) // определяем четное число символов в строке или нет
  15.             {
  16.                 result = str.Remove((str.Length / 2), 1);// метод Remove удаляет один символ с индексом
  17.             }
  18.             else
  19.             {
  20.                 result = str.Remove((str.Length / 2) - 1, 2);
  21.             }
  22.  
  23.             Console.WriteLine(result);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement