pub fn replace_placeholder(
input: &str,
placeholder: &str,
replacement: &str,
) -> StringExpand description
Replaces placeholders in a string with specified replacement values.
This function takes a string containing placeholders in the format {{placeholder}} and
replaces them with the specified replacement value. It uses regex pattern matching to
find and replace all occurrences of the placeholder.
§Arguments
input- A string slice that contains the text with placeholdersplaceholder- A string slice representing the placeholder name (without braces)replacement- A string slice containing the value to replace the placeholder with
§Returns
Returns a new String with all occurrences of the placeholder replaced with the replacement value.
§Examples
let template = "Hello {{name}}! Welcome to {{place}}.";
let result = byteutils::string::replace_placeholder(template, "name", "John");
assert_eq!(result, "Hello John! Welcome to {{place}}.");§Panics
This function will panic if the regex pattern creation fails, which should only happen if the placeholder contains characters that make an invalid regex pattern.