Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quantity of specific strings inside a string

Tags:

string

c#

.net

I'm working in .net c# and I have a string text = "Whatever text FFF you can FFF imagine"; What i need is to get the quantity of times the "FFF" appears in the string text. How can i acomplished that? Thank you.

like image 509
euther Avatar asked Feb 24 '10 16:02

euther


1 Answers

You can use regular expressions for this and right about anything you want:

string s = "Whatever text FFF you can FFF imagine";

Console.WriteLine(Regex.Matches(s, Regex.Escape("FFF")).Count);
like image 162
João Angelo Avatar answered Oct 07 '22 23:10

João Angelo