Akash Varshney
We have a string STR = “Welcome to Programming world.” Can you write a program to find out number of ‘r’ char count without using for loop ?
By Akash Varshney in .NET on Sep 26 2015
  • Sweta Shetye
    Dec, 2016 5

    string str = "Welcome to Programming World";int result = str.ToCharArray().Count(c => c == 'r');

    • 2
  • Gaurav Mishra
    May, 2016 23

    string str = "Welcome to programming world"; int charcount3 = str.Length - str.Replace("r", string.Empty).Length; Console.WriteLine(charcount3);

    • 2
  • Srinivasulu Thottempudi
    Apr, 2016 1

    int count=Regex.Matches(STR, "r").Count;

    • 2
  • Gaurav Mishra
    May, 2016 23

    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();}} }

    • 1
  • Sankar Manoharan
    Feb, 2016 17

    Try thisstring _str = "Welcome to PRogramming world";var charCount = _str.ToCharArray().Where(item => item.ToString().ToLower() == "r").Count();

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS