0

I am trying to compare a string literal with a string downloaded from a webpage.
Here is my code.

using System;
using System.Collections.Generic;
using System.Text;


namespace testsource
{
    class Program
    {
        static void Main(string[] args)
        {

            string source = getPageSource(@"http://www.mywebsite.co.uk/index.php");

            string fromsource = source;
            Console.WriteLine(fromsource); //Displays Text Here in console
            string literal = "Text Here";
            if (fromsource == literal)
            {
                Console.WriteLine("Match");
            }
            Console.ReadKey();

        }

        static string getPageSource(string URL)
        {
            System.Net.WebClient webClient = new System.Net.WebClient();
            string strSource = webClient.DownloadString(URL);
            webClient.Dispose();
            return strSource;
        }

    }
}

And my webpage code is simply this.

<?php
echo 'Text Here";
?>

Thing is, it does not match.
I have a feeling its going to be something to do with encoding, which I know nothing about.
How can I overcome this hiccup?

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Suzie999
0

Do you know that this line of code:

string strSource = webClient.DownloadString(URL);

will get the whole code of the website. So its almost impossible to compare this text with some other.
You will have to get some text out of that string.

0

The only thing returned is "Text Here"

The php I posted above is the only code on the page, there is no html, no nothing at all.

What you see there is everything.

0

Its OK I discovered, I have to knock a char off the end of the source.

I dont understand why, but my problem is solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.