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?

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.

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.