BorislavBorisov

Редици.03.02.Колко пъти символ се среща в стринг

Nov 1st, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. using System;
  2. class SymbolAppearing
  3. {
  4.     static void Main()
  5.     {
  6.         string text = "Yambol and Vidin are beautiful cities";
  7.         int index = 0, appearance = 0;
  8.         Console.Write("Indexes: ");
  9.         while((index = text.IndexOf('l', index + 1)) != -1)//търси от следващият индекс, след 'l'
  10.         {
  11.             Console.Write(index + " ");
  12.             appearance++;
  13.         }
  14.         Console.WriteLine();
  15.         Console.WriteLine("Appearance: " + appearance);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment