Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # $(1): haystack
- # $(2): needle
- #
- # Guarantees that needle appears at most once in haystack,
- # without changing the order of other elements in haystack.
- # If needle appears multiple times, only the first occurrance
- # will survive.
- #
- # How it works:
- #
- # - Stick everything in haystack into a single word,
- # with "|||" separating the words.
- # - Replace occurrances of "|||$(needle)|||" with "||| |||",
- # breaking haystack back into multiple words, with spaces
- # where needle appeared.
- # - Add needle between the first and second words of haystack.
- # - Replace "|||" with spaces, breaking haystack back into
- # individual words.
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement