Advertisement
Loloped

Praktikum

Oct 7th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. //Практикум 8, Вариант 5, задача III
  2. //Удалить из сообщения все слова, которые заканчиваются на заданный символ.
  3.  
  4. using System;
  5. using System.Text; //подключили пространство имен для работы с классом StringBuilder
  6.  
  7. namespace Hah
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             StringBuilder a = new StringBuilder("кол около колокола");
  14.             Console.WriteLine("Дана строка: {0}", a);
  15.             Console.Write("Символ: ");
  16.             char c = char.Parse(Console.ReadLine());
  17.             for (int x = 0; x < a.Length; x++)
  18.             {
  19.                 if (a[x] == ' ')
  20.                 {
  21.                     int j = x;
  22.                     int m=j;
  23.                     x++;
  24.                     while (a[x] != ' ')
  25.                     {
  26.                         m++;
  27.                     }
  28.                     if (a[m+1] == c)
  29.                     {
  30.                         a.Remove(j, m-j);
  31.                     }
  32.                 }
  33.             }
  34.             Console.WriteLine("\n {0}",a);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement