-1

I'm very beginner in C# and I would like to only extract the "title" string from a string like that: "http://playdebug.games.com/facebook/title.html"

Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90
Andre
  • 363
  • 3
  • 15
  • 3
    Guys. The man just gave an example for getting the _title_ section of an URL. What you look for is **[HERE](http://stackoverflow.com/questions/4830763/get-current-page-from-url)** – Batu.Khan Apr 09 '14 at 09:56

2 Answers2

6

I suggest going with Path.GetFileNameWithoutExtension()

String toParse = "http://playdebug.games.com/facebook/title.html";
String result = Path.GetFileNameWithoutExtension(toParse);
Andy
  • 3,997
  • 2
  • 19
  • 39
0

just get the last part via substring, position to cut is the last index of '/'. string s = "http://playdebug.games.com/facebook/title.html";

 s = s.Substring(s.LastIndexOf('/') + 1);

or the short way since it can be treated as a path ;)

 string s = Path.GetFileNameWithoutExtension("http://playdebug.games.com/facebook/title.html");
Marc Wittmann
  • 2,286
  • 2
  • 28
  • 41