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 :
3
No comments:
Post a Comment
Comments Welcome