You write the following method (line numbers are included for reference only):
You need to ensure that the method extracts a list of URLs that match the following pattern:
@http://(www\\.)?([^\\.]+)\\.com;
Which code should you insert at line 07?
A.
Option A
B.
Option B
C.
Option C
D.
Option D
Explanation:
The MatchCollection.GetEnumerator method returns an enumerator that iterates through a collection.
Note:
The MatchCollection Class represents the set of successful matches found by iteratively applying a regular
expression pattern to the input string.
Incorrect:
Not B: The ICollection.SyncRoot property gets an object that can be used to synchronize access to the
ICollection.
MatchCollection.GetEnumerator Method
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchcollection.getenumerator
(v=vs.110).aspx
answer is C!
C, verified.
C
Who was checking this answers before accepting these questions? Like 50% of it are wrongly answered.
The answer is C
Please find the below code
class Program
{
static void Main(string[] args)
{
Question11 q11 = new Question11();
List strList = Question11.TestIfWebSite(“https://www.gmail.com”);
Console.ReadKey();
}
}
public class Question11
{
public static List TestIfWebSite(string url)
{
const string pattern = @”http://(www\\.)?([^\\.]+)\\.com”;
List list = new List();
MatchCollection matches = Regex.Matches(url,pattern);
list = (from Match m in matches select m.Value).ToList();
return list;
}
}
Ans is : C
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Question11 q11 = new Question11();
List strList = Question11.TestIfWebSite(“http://www.gmail.com”);
Console.ReadKey();
}
}
public class Question11
{
public static List TestIfWebSite(string url)
{
const string pattern = @”http://(www\.)?([^\.]+)\.com”;
List list = new List();
MatchCollection matches = Regex.Matches(url, pattern);
list = (from Match m in matches select m.Value).ToList();
//foreach(var mat in matches)
//{
// list.Add(mat.ToString());
//}
return list;
}
}
}
static void Main(string[] args)
{
Question11 q11 = new Question11();
List strList = Question11.TestIfWebSite(“http://www.gmail.com http://www.hotmail.com“);
foreach (var item in strList)
{
WriteLine(item);
}
Console.ReadKey();
}
public class Question11
{
public static List TestIfWebSite(string url)
{
const string pattern = “http://(www\\.)?([^\\.]+)\\.com”;
List list = new List();
MatchCollection myMatches = Regex.Matches(url, pattern);
list = (from Match m in myMatches select m.Value).ToList();
return list;
}
}