3 May 2026

Find number of occurence of string in Text in C#

 Find number  of occurence of string in Text in C#


using System;

public class HelloWorld
{
    public static void Main(string[] args)
    {
       string text = "appleorangeapplebananaappleapp";
       string pattern = "apple";

int count = text.Split(new[] { pattern }, StringSplitOptions.None).Length - 1;

Console.WriteLine(count);
    }

 Output :

No comments:

Post a Comment

Comments Welcome

Find number of letter occurence of all letter in c#

  Find number of letter occurence of all letter in c#  namespace ConsoleApp1 {     internal class Program     {         static void Main(st...