+ Reply to Thread
Results 1 to 3 of 3

Thread: ways of setting a page title

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    36

    ways of setting a page title

    I was wondering if there are other ways to set the page title , instead of the <title>XXX</title> ?
    And how to read the pages titles innertext by all kind of ways ?

  2. #2
    There are actually two ways of setting the page title that i am aware of

    1) <title>xxxxx</title>
    2) <meta name="title" content="xxxxx" />

    And the best method to read the title innertext for these 2 methods are :

    First define the Regex patterns :
    Code:
            Regex r1 = new Regex(@"<title>.*</title>");
            Regex r2 = new Regex(@"<meta name=" + '"' + "title" + '"' + " content=" + '"' + ".*" + '"' + ".*/>");
    Then
    Code:
    		string text = File.ReadAllText("file.html");
            if (match1.Success)
            {
                string title = match1.Value;
    							
    			title = title.Replace("<title>", "");
                title = title.Replace("</title>", "");
    							
    		    // finally title will be XXXXX without the title tags
    		}
    						
    		else if (match2.Success)
            {
                string title = match2.Value;
    							
    			Regex regremp = new Regex('"' + ".*/>");
                Match mtemp = regremp.Match(title);
                title = title.Replace(mtemp.Value, "");
    							
    			// finally title will be XXXXX without the meta tag
    		}
    Last edited by csharpmaster; 06-28-2012 at 08:20 PM.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    36
    Thank you so much , it works very fine.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts