> public static class StringMethods > { > public static IEnumerable<int> EnumAt(string searchIn, string searchFor, int startIndex, StringComparison comparison) > { > int offset = startIndex; > > while ((offset = searchIn.IndexOf(searchFor, offset, comparison)) != -1) > { > yield return offset; > offset += searchFor.Length; > } > } > } >>
> public static class MyClass > { > static string htmlSample = @" > <!DOCTYPE html> > > <html lang=""en-GB""> > <head> > <meta charset=""utf-8""> > <title>Example of an inline image</title> > </head> > <body> > <imG src=""balconyview.jpg""> > <Img Src = 'balconyview.jpg' alt='View from my balcony, showing a row of houses, trees and a castle'> > <iMg src='http://example.com/brokenlink/sunset.gif' alt='Beautiful Sunset' /> > > </body> > </html> > "; > > public static void Main() > { > foreach (int index in StringMethods.EnumAt(htmlSample, "<img", 0, StringComparison.InvariantCultureIgnoreCase)) > { > Console.WriteLine("{0} {1}", index, htmlSample.Substring(index, 4)); > } > Console.ReadLine(); > } > } >Thanks, I will keep this as a reference.