string input = "http://www.somesite.com/somepage.aspx?whatever"; int index = input.LastIndexOf("/"); if (index >= 0) input = input.Substring(0, index); // or index + 1 to keep slash