Puede utilizar split
método de string
clase para dividirlo en /
Pruebe esto si usted quiere recoger página Guía
string words = "http://www.example.com/directory1/directory2/default.aspx";
string[] split = words.Split(new Char[] { '/'});
string myDir=split[split.Length-2]; // Result will be directory2
Aquí es ejemplo de MSDN. Cómo usar el método split
.
using System;
public class SplitTest
{
public static void Main()
{
string words = "This is a list of words, with: a bit of punctuation" +
"\tand a tab character.";
string [] split = words.Split(new Char [] {' ', ',', '.', ':', '\t' });
foreach (string s in split)
{
if (s.Trim() != "")
Console.WriteLine(s);
}
}
}
// The example displays the following output to the console:
// This
// is
// a
// list
// of
// words
// with
// a
// bit
// of
// punctuation
// and
// a
// tab
// character
Es posible que desee ser un poco más preciso: ¿Quieres el último subdirectorio antes de la página? es decir, si la URL era 'http: // www.abc.com/foo/bar/baz/default.aspx', ¿querrías' baz'? – Filburt
Por favor, mira mi respuesta actualizada. – jams