View Single Post
  #1 (permalink)  
Old Nov 14th, 2007, 21:17
alexgeek's Avatar
alexgeek alexgeek is offline
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
[SOLVED] [C#] Having some problems.

Creating a web application that finds some tags and displays them
I've run into some errors and I'm completely stuck!

Here is my code:
Code: Select all
using System;
using System.Text.RegularExpressions;

struct info
{
    public string output;
    public Match header;
    public Match title;
    public string URL;
    public void results()
    {
        Console.WriteLine("-=-RESULTS-=-");
        Console.WriteLine("Website Page Title (title): {0}", title);
        Console.WriteLine("Website header (h1): {0}", header);
    }
    public static Match find(string reg) {
        Regex r = new Regex(reg);
        Match m = r.Match(output);
        return m;
    }
}

class WebApp
{
    public static void Main()
    {
        info web;
        System.Console.Write("Enter a URL to analyze then press enter.\n e.g. http://www.alexgeek.co.uk \n >");
        string input = System.Console.ReadLine();
        if (input == null)
        {
            web.URL = "http://www.alexgeek.co.uk";
        }
        else
        {
            web.URL = input;
        }
        web.output = new System.Net.WebClient().DownloadString(web.URL);
        web.header = web.find(@"<h1>(.)+</h1>");
        web.results();
    }
}
And the errors:
Code: Select all
fileWrite.cs(19,27): error CS0120: An object reference is required for the
        nonstatic field, method, or property 'info.output'
fileWrite.cs(7,19): (Location of symbol related to previous error)
fileWrite.cs(40,22): error CS0176: Static member 'info.find(string)' cannot be
        accessed with an instance reference; qualify it with a type name instead
fileWrite.cs(17,25): (Location of symbol related to previous error)
I've not a clue what do! Please help
Reply With Quote