Fsharp: Replace String

By Xah Lee. Date: . Last updated: .

Replace string

// replace string

let xx = "i saw a butterfly 🦋."
let xresult = xx.Replace("butterfly 🦋", "ladybug 🐞")
printfn "%s" xresult
// i saw a ladybug 🐞.

Replace text by regex. ignore case

// replace text by regex. ignore case

open System.Text.RegularExpressions
let xtext = "Cats, lots cats."
let xout = Regex.Replace(xtext, "cat", "dog", RegexOptions.IgnoreCase)
printfn "%s" xout
// dogs, lots dogs.