I think you want can benefit of the Uri object the framework provides.
It does not provide the whole solution (segments ending with "/"), but it does most of the job.
List<string> strings = new List<string>
{
"https://linkedin.com/in/username",
"https://www.facebook.com/username",
"username",
"https://plus.google.com/u/0/username/"
};
List<Tuple<int, string>> results = new List<Tuple<int, string>>();
for (int i = 0; i < strings.Count; i++)
{
var s = strings.ElementAt(i);
try
{
Uri uri = new Uri(s);
var lastSegment = uri.Segments.LastOrDefault();
if (!lastSegment.EndsWith("/") && !string.IsNullOrEmpty(lastSegment))
results.Add(new Tuple<int, string>(i, lastSegment));
}
catch (Exception ex)
{
//s is not a valid uri and thus a valid uri object could not be created out of it
results.Add(new Tuple<int, string>(i, ex.Message));
}
}
foreach (var segment in results)
Console.WriteLine(segment);
Output: (tuples where the number is the element index in your sample)
(the last element is not added because you do not want segments ending with /)

Substringbased onlastIndexOfif (url.Contains("/") && !url.EndsWith("/")) { result = url.Substring(url.LastIndexOf('/') + 1); }- and so on, just add the necessary logic for those strings that do not contain/System.Urihas some useful features you may use.