Fork me on GitHub
#beginners
<
2017-02-27
>
jeffmk00:02:35

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)?

lgessler00:02:01

@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

jeffmk00:02:32

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

lgessler01:02:51

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

lgessler01:02:16

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

jeffmk01:02:57

@lgessler Perhaps last-index-of instead.

jeffmk01:02:04

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

josh_tackett19:02:29

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

sveri21:02:16

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