Apply a function on a given set of elements of a character string.

applyString(x, FUN, pos = NULL, pattern = NULL)

Arguments

x

a character vector, or a vector to be coerced to a character vector.

FUN

the function to be applied, see base::lapply().

pos

a vector indicating the elements position.

pattern

a pattern see base::gregexpr().

Value

A character vector.

Note

In case both pos or pattern, the latter is ignored.

Examples

applyString('cool', pos = 1:2, FUN = toupper)
#> [1] "COol"
applyString(c('cool', 'pro'), pattern = 'o', FUN = toupper)
#> [1] "cOOl" "prO"