Count occurrences of a substring: Difference between revisions

added C sharp
(Added Delphi example)
(added C sharp)
Line 91:
2
</pre>
 
=={{header|C sharp}}==
<lang c sharp>
public static int CountSubStrings(string testString, string testSubstring)
(
int location = 0;
int count = 0;
while (location < testString.Length)
{
int found = testString.IndexOf(testSubstring, location);
if (found == -1)
{
break;
}
else
{
count++;
location = location + testSubstring.Length;
}
}
return count;
}</lang>
 
=={{header|D}}==
<lang d>import std.stdio, std.algorithm;
Anonymous user