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.IO;
- namespace _25.ExtractTagsInfo
- {
- class ExtractTagsInfo
- {
- static void Main()
- {
- StreamReader reader = new StreamReader("test.html");
- string fileContent = null;
- using (reader)
- {
- fileContent = reader.ReadToEnd();
- }
- string newString = fileContent;
- int leftBrackets = fileContent.Length - fileContent.Replace("<", "").Length;
- int rightBrackets = fileContent.Length - fileContent.Replace(">", "").Length;
- if (leftBrackets == rightBrackets)
- {
- for (int i = 0; i < leftBrackets; i++)
- {
- int lastLeftBracketIndex = newString.LastIndexOf("<");
- int matchingRigthBracketIndex = newString.IndexOf(">", lastLeftBracketIndex);
- if (matchingRigthBracketIndex - lastLeftBracketIndex < 1)
- {
- Console.WriteLine("The html file {0} is incorrect:", fileContent);
- return;
- }
- else
- {
- newString = newString.Remove(lastLeftBracketIndex, matchingRigthBracketIndex - lastLeftBracketIndex + 1);
- }
- }
- string[] words = newString.Split(new string[]{" ","\r\n"},StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < words.Length; i++)
- {
- Console.Write("{0} ",words[i]);
- }
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine("The html file:\n {0} is incorrect:", fileContent);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement