string str = "Welcome to Programming World";int result = str.ToCharArray().Count(c => c == 'r');
string str = "Welcome to programming world"; int charcount3 = str.Length - str.Replace("r", string.Empty).Length; Console.WriteLine(charcount3);
int count=Regex.Matches(STR, "r").Count;
Both the answers posted below are correct. using System; using System.Linq; using System.Text.RegularExpressions;namespace DemoConsoleApp {class Program{static void Main(string[] args){string str = "Welcome to programming world";int count = Regex.Matches(str, "r").Count;Console.WriteLine(count);var charCount = str.ToCharArray().Where(item => item.ToString().ToLower() == "r").Count();Console.WriteLine(charCount);Console.ReadKey();}} }
Try thisstring _str = "Welcome to PRogramming world";var charCount = _str.ToCharArray().Where(item => item.ToString().ToLower() == "r").Count();