Function replace

Source
pub fn replace(
    text: &String,
    search_string: &String,
    replacement: &String,
) -> String
Expand description

Replaces all occurrences of a search string within a given text with a replacement string.

§Arguments

  • text - The original string where the search and replace will be performed.
  • search_string - The substring that will be searched for within the text.
  • replacement - The string that will replace each occurrence of the search string.

§Returns

A new String with all occurrences of the search string replaced by the replacement string.

§Examples

use rust_string_utils::replace;
let result = replace(&String::from("hello world"), &String::from("world"), &String::from("Rust"));
assert_eq!(result, "hello Rust");