views:

41

answers:

1

I have this method that receives an ID number and downloads an HTML website according to that ID.

Typically, an IMDB link is like this:

http://www.imdb.com/title/tt0892791/
http://www.imdb.com/title/tt1226229/
http://www.imdb.com/title/tt0000429/

They all follow the 'tt' then 7 digits, with lack of digits turning into zeroes to fill out the left spaces.

How can I accomplish this using C#? I'm kind of stumped.

Here's my method:

/// <summary>
/// Find a movie page using its precise IMDB id.
/// </summary>
/// <param name="id">IMDB Movie ID</param>
/// <returns>Returns an HtmlDocument with the source code included.</returns>
public HtmlDocument ByID(string id)
{
    string url = String.Format("http://www.imdb.com/title/tt{0}/", id);            
    HtmlDocument page = downloader.Load(url);
    return page;
}

Thank you very much for your time, and if you are interested in helping out, you can check out the complete source code of TheFreeIMDB here: http://thefreeimdb.codeplex.com/

+8  A: 

Since id is a string in your sample, use id.PadLeft(length, '0'), where length is the total length you want (in this case: 7).

Anthony Pegram
Worked exactly how I wanted it to. Thank you! Wait for time to pass and I'll accept the answer. It's 8 minutes until I can do that.
Sergio Tapia