Fork me on GitHub

Need to do the opposite of clojure.string/replace-first (i.e., replace-last, which doesn’t exist). Is there a better solution than doing something like: (s/reverse (s/replace-first (s/reverse “foo”) “o” “O”)) (where I want to convert “foo” to “foO”, and s is clojure.string)?


@jeffmk one alternative might be to scan the string with repeated calls to index-of until you get nil, and then to append everything before the index to a call to replace on everything after the index. i'm not sure how that would fare performance wise in comparison to your method though since strings are immutable


@lgessler Thanks. I have to think that would be faster than reversing a string 2x.


yeah probs, I'm sure there's a much more elegant solution out there one of the clojure gurus in this channel could give though


I just realized, make sure to use the from-index param with index-of otherwise the algo is strictly speaking O(n^2)


@lgessler Perhaps last-index-of instead.


Unfortunately I really need regex support, so for now reversing the string 2x may be good enough.


Anyone on here work for Atlassian / bitbucket we are having issues with not having enough seats for users but we have permission for 25 and we only have 9 users right now


@josh_tackett Are you sure you are on the correct slack?