.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

search through HTML using C#

Posted By: AljurC     Posted Date: November 06, 2010    Points:2   Category :C#
Hi! I came across this site. I would like to know if you could help me with a school assignment. The program should be written in C#. File source would be coming from an .html file

Source HTML Code:
<HTML>
<Title>HELLO</Title>
<Body>HELLO WORLD</Body>
<HTML>


Enter an HTML Tag: body
Output:
HELLO WORLD

Enter an HTML Tag: html
Output:
<Title>HELLO</Title>
<Body>HELLO WORLD</Body>

Responses
Author: Asha.MP             
Posted Date: November 07, 2010     Points: 5   

Hi..

please try this.

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;


public class HtmlFileRead
{
public static void main()
{
'E:\\Extra\\Develop\\WindowsApplication1\\Genaral(Console)\\HtmlFile.Html this is html file path
StreamReader f = new StreamReader("E:\\Extra\\Develop\\WindowsApplication1\\Genaral(Console)\\HtmlFile.Html");

Console.WriteLine("Enter HTML tag to search");
string htmlTag = Console.ReadLine();
string str = f.ReadToEnd().ToString();
Match m = Regex.Match(str, "<" + htmlTag + ">" + "(.*)" + "</" + htmlTag + ">", RegexOptions.Singleline);
Console.WriteLine(m.Groups[0]);
Console.ReadLine();
}
}


Thanks and Regards,
Asha.mp


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend