URL Validation
This is a simple URL Validation Application written in C#
Click here for a complete article:
http://www.devtalklive.com/cmsnet/CDA/StoryPg.aspx?ID=13&Ver=2
using System;
namespace CSharpProj {
public class WebSite
{
const string http = @"http//";
const string httpwww = @"http://www.";
string siteName;
string url;
string description;
public WebSite(): this("No Site", "No url", "No Description"){}
public WebSite(string newSite): this(newSite, "No url", "No Description"){}
public WebSite(string newSite, string newURL): this(newSite, newURL,
"No Description"){}
public WebSite(string newSite, string newURL, string newDesc)
{
this.siteName = newSite;
this.url = newURL;
this.description = newDesc;
Console.WriteLine(this.siteName + " " + this.url + " " + this.description)
;
}
public string ValidateUrl(string url)
{
if ((url.StartsWith("www.")))
{
return "[Passed without,so adding http]--> " + http + url;
}
if (!(url.StartsWith(httpwww)))
{
return "[Passed without,so adding httpwww]--> " + httpwww + url;
}
return "[Passed with httpwww]--> " + url;
}
public string ValidateUrl(ref string url)
{
if ((url.StartsWith("www.")))
{
return url = http + url;
}
if (!(url.StartsWith(httpwww)))
{
return url = httpwww + url;
}
return url;
}
}
public class WebSiteTester
{
static void Main()
{
string url = "google.com";
WebSite web = new WebSite("Hotmail", "http://www.hotmail.com");
string myurl = web.ValidateUrl("http://www.yahoo.com");
Console.WriteLine(myurl);
Console.WriteLine("Before: " + url);
web.ValidateUrl(ref url);
Console.WriteLine("After: " + url);
DateTime dt = Convert.ToDateTime("8/1/2005");
Console.WriteLine(string.Format("{0:MMMM yyyy}", dt));
//would print August 2005
}
}
}