str_replace_nth: Replace nth occurring pattern in a string

View source: R/str_replace_nth.R

str_replace_nthR Documentation

Replace nth occurring pattern in a string

Description

A more refined replacement function than 'str_replace()' and 'str_replace_all()'

Usage

str_replace_nth(x, pattern, replacement, n)

Arguments

x

Pass string character

pattern

String containing characters to match

replacement

String containing characters to replace.

n

Nth term to be replaced

Examples

x <- "pineapplepie"
str_replace_nth(x = x, pattern = "p", replacement = "q", n = 2)

str_replace_nth(x = "pigpig", pattern = "pig", replacement = "dog", n = 2)

str_replace_nth(x = "pigpig", pattern = "pig", replacement = "gy", n = 2)


martinctc/textworks documentation built on Oct. 5, 2022, 8:09 p.m.