Skip to contents

Splits character vectors into substrings. This is a convenience wrapper around stringi::stri_split_fixed() and stringi::stri_split_regex() with simplified defaults.

Usage

strSplit(x, split = "", fixed = FALSE)

Arguments

x

a character vector to be split

split

a character string specifying the delimiter (if fixed = TRUE) or a regular expression (if fixed = FALSE)

fixed

logical; if TRUE, split is treated as a fixed string. Otherwise, it is interpreted as a regular expression.

Value

A list of character vectors. If x has length 1, a character vector is returned.

Details

If the input x has length 1, the result is returned as a character vector instead of a list for convenience.

This function provides a simplified interface to string splitting using the stringi package. It avoids some of the complexity of base::strsplit() while providing consistent and Unicode-aware behavior.

See also

Examples

strSplit("a,b,c", ",", fixed = TRUE)
#> [1] "a" "b" "c"

strSplit(c("a b", "c d"), " ")
#> [[1]]
#> [1] "a" "b"
#> 
#> [[2]]
#> [1] "c" "d"
#> 

# regex splitting
strSplit("a1b2c3", "\\d")
#> [1] "a" "b" "c" ""