Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using System.Text.RegularExpressions;
- namespace NoHTMLtags
- {
- class NoHTMLtags
- {
- // с любезното съдействие на http://www.dotnetperls.com/remove-html-tags
- /// <summary>
- /// Remove HTML tags from string using char array.
- /// </summary>
- public static string StripTagsCharArray(string source)
- {
- char[] array = new char[source.Length];
- int arrayIndex = 0;
- bool inside = false;
- for (int i = 0; i < source.Length; i++)
- {
- char let = source[i];
- if (let == '<')
- {
- inside = true;
- continue;
- }
- if (let == '>')
- {
- inside = false;
- continue;
- }
- if (!inside)
- {
- array[arrayIndex] = let;
- arrayIndex++;
- }
- }
- return new string(array, 0, arrayIndex);
- }
- static void Main(string[] args)
- {
- WebClient webCilent = new WebClient();
- webCilent.Encoding = System.Text.Encoding.UTF8; //указва форматирането на текста - без него излизат маймуници особенно на кирилица
- string sorceStr = webCilent.DownloadString("http://forums.academy.telerik.com/54788/c%23-%D0%B4%D0%BE%D0%BC%D0%B0%D1%88%D0%BD%D0%BE-strings-and-text-processing-25-%D0%B7%D0%B0%D0%B4%D0%B0%D1%87%D0%B0");
- string stripSourceStr = StripTagsCharArray(sorceStr).Trim();
- Dictionary<string, int> dictionary = new Dictionary<string, int>();
- StringBuilder wordStrTotal = new StringBuilder();
- foreach (var word in Regex.Matches(stripSourceStr, @"\w+"))
- {
- string wordStr = Convert.ToString(word);
- wordStrTotal.Append(wordStr + ' ');
- #region Проверява дължината на думат, проверява дали съществува и я добавя
- //if (wordStr.Length > 0)
- //{
- // if (dictionary.ContainsKey(wordStr))
- // {
- // dictionary[wordStr]++;
- // }
- // else
- // {
- // dictionary.Add(wordStr, 1);
- // }
- //}
- #endregion
- }
- #region Принтира на екрана думите който са в речника
- //foreach (KeyValuePair<string, int> item in dictionary)
- //{
- // Console.WriteLine("{0,15} -> {1}", item.Key, item.Value);
- //}
- #endregion
- Console.ReadLine();
- #region Принтира Съдържанието на СтрингБуилдера
- Console.WriteLine(wordStrTotal.ToString());
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement