February 11th, 2009
Manipulating Strings in C# – Finding all occurrences of a string within another string - 2
A common programming problem is to find the position of all copies of a string in another string. For finding the first copy the C# string method IndexOf is similar to the C strpos() function. It returns the first occurrence of a string in another string. But what if you would like to find the position of all occurances of the substring? The following “IndexOfAll” method does just that. It returns an IEnumerable containing the offsets of each sub-string in the main string.



Except where otherwise noted, content on this site is