I know the basics of List and IEnumerator but still I confused with this. I want to search valid URLs from a string. I can extract the valid URLs by LINQ but I would like to use IEnumerator GetEnumerator() of MatchCollection.
string url = @"http://www.ms.com http://www.hemelix.com http://www.cgi.com";
string pattern = @"http://(www\.)?([^\.]+)\.com";
List<string> result = new List<string>();
MatchCollection myMatches = Regex.Matches(url, pattern);
result = (
from System.Text.RegularExpressions.Match m in myMatches
select m.Value
).ToList<string>();
var result2 = from Match m in myMatches
select m.Value;
foreach (var item in result2)
{
Console.WriteLine(item.ToString());
}
// Does the following code work in this case??
result = (List<string>)myMatches.GetEnumerator();
// OR the following
IEnumerator<string> enumerator = (IEnumerator<string>) (myMatches.GetEnumerator());
while (enumerator.MoveNext())
{
Console.WriteLine(enumerator.Current);
}