I have a string object in c# with a bunch of elements delimited by '/' characters. The string will look something like this:
"element1/element2/element3/element4"
What's the most efficient way to change the last element in the '/' delimited string?
Use string.LastIndexOf:
string s = "element1/element2/element3/element4";
s = s.Substring(0, s.LastIndexOf('/') + 1) + "foo";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With