Globally replace text in several files: Difference between revisions
Globally replace text in several files (view source)
Revision as of 11:41, 3 July 2021
, 2 years ago→{{header|Haskell}}: Added a variant implementation of `replace`
(→{{header|Haskell}}: Added a variant implementation of `replace`) |
|||
Line 679:
| a `isPrefixOf` xxs = b <> go (drop w xxs)
| otherwise = x : go xs</lang>
and with different library imports, we could also write things like:
<lang haskell>import Data.List (intercalate)
import Data.List.Split (splitOn)
replace :: String -> String -> String -> String
replace a b = intercalate b . splitOn a</lang>
'''Example:'''
<pre>
|