Original Response:
Converting the string to a Uri object, you can do the following:
//filePath = @"http://s.ion.com/abc/Std/isd/text.txt"
Uri uri = new Uri(filePath);
string output = uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - uri.Segments.Last().Length - 1); // -1 removes the '/' character at the end
// output = "http://s.ion.com/abc/Std/isd"
*Note: the Last() function is from the System.Linq library. If you are not using this library, you can still obtain the last segment by replacing uri.Segments.Last().Length with uri.Segments[uri.Segments.Length - 1].Length.
Updated Response based on this comment:
//filePath = @"http://s.ion.com/abc/Std/isd/ser/wer/text.txt"
Uri uri = new Uri(filePath);
string output = uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - uri.Segments.[uri.Segments.Length - 3].Length - 1);
// uri.Segments.Length - 3 removes the last 3 unrequired "segments"
// -1 removes the '/' character at the end
// output = "http://s.ion.com/abc/Std/isd"
Updated Response based on the last revision:
//filePath = @"http://s.ion.com/abc/Std/isd/wer/we/wed/sa/ser/text.txt"
Uri uri = new Uri(filePath);
string output = uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - uri.Segments.[uri.Segments.Length - 6].Length - 1);
// uri.Segments.Length - 6 removes the last 6 unrequired "segments"
// -1 removes the '/' character at the end
// output = "http://s.ion.com/abc/Std/isd"
If those three strings are possible, then you can do a conditional statement to ascertain which string to manipulate.
if (/* string 1 */)
// see original response
else if (/* string 2 */)
// see first updated response
else if (/* string 3 */)
// see second updated response