==========================
==========================
using System.Text;
using System.Net;
using System.IO;
namespace SearchProject
{
class ReadWeb
{
public static string ReadURL(string
url)
{
// used to build entire input
StringBuilder sb = new
StringBuilder();
// used on each read operation
byte[] buf = new byte[8192];
// prepare the web page we will be asking for
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(url);
// execute the request
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
// we will read data via the response stream
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);
// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf,
0, count);
// continue building the string
sb.Append(tempString);
}
}
while (count > 0); //
any more data to read?
// print out page source
return (sb.ToString());
}
}
}
==========================
RegexTest.cs
==========================
==========================
using System;
using System.IO;
using System.Collections.Generic;
namespace SearchProject
{
class RegexTest
{
static string
bacaFile(string namaFile)
{
String teksSumber = String.Empty;
if (File.Exists(namaFile))
teksSumber =
File.ReadAllText(namaFile);
else
Console.WriteLine("File tidak ditemukan");
return teksSumber;
}
static string
ambilResult()
{
String namaFile = Directory.GetCurrentDirectory()
+
@"\..\..\Cerita Kancil.txt";
String teksSumber = bacaFile(namaFile);
//Penggunaan Objek
HasilSearchRegex objSearch = new HasilSearchRegex();
objSearch.keyword = @"(?i)([a-z]+)-\1";
//objSearch.keyword = @"(?i)(kancil|harimau)";
return objSearch.getConsoleResult(teksSumber);
}
static void Main(string[] args)
{
//ReadWeb objWeb = new ReadWeb();
String teksSumber = ReadWeb.ReadURL("http://www.klikbca.com");
//Console.WriteLine(teksSumber.ToString());
//Console.Write(hasil);
//String namaFile = Directory.GetCurrentDirectory() +
//
@"\..\..\Cerita Kancil.txt";
//String teksSumber = bacaFile(namaFile);
////Penggunaan Objek
HasilSearchRegex objSearch = new HasilSearchRegex();
//objSearch.keyword = @"(?i)([a-z]+)-\1";
objSearch.keyword = @"<td.+kurs.+?>(.+?)</td>";
//objSearch.getConsoleResult(teksSumber);
////
Console.WriteLine(objSearch.getConsoleResult(teksSumber));
Console.ReadLine();
}
}
}
No comments:
Post a Comment