Select last element quickly after a .Split()

If you’re using .NET 3.5 or higher, it’s easy using LINQ to Objects:

stringCutted = myString.Split("https://stackoverflow.com/").Last();

Note that Last() (without a predicate) is optimized for the case where the source implements IList<T> (as a single-dimensional array does) so this won’t iterate over the whole array to find the last element. On the other hand, that optimization is undocumented…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)