Can anyone point me in the direction of functionality that will provide the number of times a String contains a given substring? Preferably in C# and/or built in to the .Net framework...
String.Contains Count?
Collapse
X
-
For anyone interested, this is what I ended up using:
public Int32 ContainsCount(S tring SearchPhrase, String SearchText) {
String Remains = SearchText;
Int32 NewIndex = 0;
Int16 Count = 0;
while (Remains.Length >= SearchPhrase.Le ngth)
{
NewIndex = Remains.IndexOf (SearchPhrase);
if (NewIndex >= 0)}
{
Count++;
Remains = Remains.Substri ng(NewIndex + SearchPhrase.Le ngth);
}
else
{
return Count;
}
return Count;
}
Comment
Comment