/Prelude-v21.1.0/Text/replace.dhall

Copy path to clipboard

Examples

replace "-" "_" "foo-bar" โ‰ก "foo_bar"
replace "๐Ÿ’ฃ" "๐Ÿ’ฅ" "๐Ÿ’ฃ๐Ÿ’ฃ๐Ÿ’ฃ" โ‰ก "๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ"
replace "๐Ÿ‘จ" "๐Ÿ‘ฉ" "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ" โ‰ก "๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"

Source

{-
Replace a section of `Text` with another inside a `Text` literal.
-}
let replace
: โˆ€(needle : Text) โ†’ โˆ€(replacement : Text) โ†’ โˆ€(haystack : Text) โ†’ Text
= Text/replace

let example0 = assert : replace "-" "_" "foo-bar" โ‰ก "foo_bar"

let example1 = assert : replace "๐Ÿ’ฃ" "๐Ÿ’ฅ" "๐Ÿ’ฃ๐Ÿ’ฃ๐Ÿ’ฃ" โ‰ก "๐Ÿ’ฅ๐Ÿ’ฅ๐Ÿ’ฅ"

let example2 = assert : replace "๐Ÿ‘จ" "๐Ÿ‘ฉ" "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ" โ‰ก "๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"

in replace