Advertisement
myname0

Практикум8_II_8

Oct 22nd, 2015
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1.                static int Surch(String s, StringBuilder t)
  2.         {
  3.             int i = 0;
  4.             int j = 0;
  5.             int ssize = s.Length;
  6.             int tsize = t.Length;
  7.             while ((i <= (tsize - ssize)) && (j < ssize))
  8.             {
  9.                 if (t[i + j] == s[j])
  10.                 {
  11.                     j++;
  12.                 }
  13.                 else
  14.                 {
  15.                     i++;
  16.                     j = 0;
  17.                 }
  18.             }
  19.             if (j == ssize)
  20.                 return i;
  21.             else return -1;
  22.         }
  23.  
  24.         static void Main(string[] args)
  25.         {
  26.             Console.Write("Enter string: ");
  27.             StringBuilder str = new StringBuilder(Console.ReadLine());
  28.             Console.Write("Enter substring: ");
  29.             String substr = Console.ReadLine();
  30.             while (Surch(substr, str) != -1)
  31.             {
  32.                 str.Remove(Surch(substr, str), substr.Length);
  33.             }
  34.             if(str.Length == 0)
  35.                 Console.WriteLine("Удалили все симаолы из строки.");
  36.             else Console.WriteLine(str);              
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement