PrepAway - Latest Free Exam Questions & Answers

You need to ensure that the method extracts a list of U…

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?

PrepAway - Latest Free Exam Questions & Answers

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

9 Comments on “You need to ensure that the method extracts a list of U…

  1. Seamus says:

    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;
    }
    }




    5



    0
  2. mahesh says:

    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;
    }
    }
    }




    5



    0
  3. Stanger says:

    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;
    }
    }




    1



    0

Leave a Reply