07 July 2010
Code : Strip HTML (Remove HTML Tags)
string StripHTML(string htmlString)
{
//This pattern Matches everything found inside html tags;
//(.|\n) - > Look for any character or a new line
// *? -> 0 or more occurences, and make a non-greedy search meaning
//That the match will stop at the 1st available '>' it sees, and not at the last one
//(if it stopped at the last one we could have overlooked
//nested HTML tags inside a bigger HTML tag..)
string pattern = @"<(.|\n)*?>";
return Regex.Replace(htmlString, pattern, string.Empty);
}
Posted by আলোর ছটা at 10:01 PM 0 comments
Beginner's Unit Testing in C# using NUnit
C# .NET 2.0 Test Driven Development
The above website is helpful for a beginner though some steps could have been clearer.
Posted by আলোর ছটা at 9:55 PM 0 comments
Code : Download a web page
/// Returns the content of a given web adress as string./// /// URL of the webpage
/// Website content
public static string DownloadWebPage(string Url)
{
// Open a connection
HttpWebRequest WebRequestObject = (HttpWebRequest)HttpWebRequest.Create(Url);
// You can also specify additional header values like
// the user agent or the referer:
WebRequestObject.UserAgent = ".NET Framework/2.0";
WebRequestObject.Referer = "http://www.example.com/";
// Request response:
WebResponse Response = WebRequestObject.GetResponse();
// Open data stream:
Stream WebStream = Response.GetResponseStream();
// Create reader object:
StreamReader Reader = new StreamReader(WebStream);
// Read the entire stream content:
string PageContent = Reader.ReadToEnd();
// Cleanup
Reader.Close();
WebStream.Close();
Response.Close();
return PageContent;
}
Posted by আলোর ছটা at 9:46 PM 0 comments
Subscribe to:
Posts (Atom)