Monday, 27 February 2023

To find the occurrence of a character in a string in C#, you can use the Count method of the String class, which returns the number of occurrences of a specified character in the string. 


Here is the code snippet for your reference:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace find_occurence_of_characters_in_string
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter the string");
            string ste = Console.ReadLine();
            Console.WriteLine("Enter the character to find its occurence:");
            string character = Console.ReadLine();
            char ch = character.ToCharArray()[0];
            int count = ste.Count(o => o == ch);
            Console.WriteLine("Character '{0}' - occurence {1}", ch, count);
            Console.ReadLine();
        }
    }
}


In this example, the Count method is called on the string str, with a lambda expression that checks if each character in the string is equal to the specified character ch. The resulting count is stored in the count variable, which is then displayed using the Console.WriteLine method.



How to find the occurrence of a character in a string in C# | TechnicalTalks

To find the occurrence of a character in a string in C#, you can use the Count method of the String class, which returns the number of occur...

Friday, 10 February 2023

Abstraction in C#: An Overview of Key Concepts

Thursday, 9 February 2023

What are the OOPs concepts in C#? | Most asked C# Interview Questions

 

Technical Talks © 2015 - Designed by Templateism.com, Distributed By Blogger Templates