URL Parser in .NET RRS feed

  • Question

  • Hi Team,

    I need to implement the url parser in .net framework. when a url is inputted, the application should display the number of images , count of words and most used words in the given url.

    Please provide the best possible solution or any plug in available.

    Please remember to click Mark as Answer on the answer if it helps you

    Monday, August 13, 2018 5:51 PM

All replies

  • First, you use System.Net.WebClient.DownloadFile() or .DownloadString to download the content.

    To count the number of images, count the occurance of "<img" with RegEx.Matches().

    To count the number of characters, use String.Split() on ' ' with RemoveEmptyEntries. You may want to add some String.Replace() to replace certain symbol with space (say, "," to " ") to ensure it's properly tokenized. And then return the length of resulting array.

    To found the most used word, I'd loop against the previously generated tokenized array, and use a Dictionary<string, int> to store occurance of each word. Finally use .Select(x => x.Value).Max() to get the max occurance count, and output all word within the Dictionary with the matching count with something like:

    int maxcnt = result.Select(x => x.Value).Max(); foreach (string word in result.Where(x => x.Value == maxcnt).Select(y => y.Key)) { Console.WriteLine(word); } //or the following to store the result directly in array: string[] maxOccWords = result.Where(x => x.Value == maxcnt).Select(y => y.Key).ToArray();

    Replace Console.WriteLine() with statement to store the outcome.

    Tuesday, August 14, 2018 1:53 AM