Skip to contents

Counts number of pieces of a string separated by a pattern. If it's an empty string, returns 0. If the pattern isn't found, returns 1. If the pattern is found once, returns 2 (two pieces), etc.

Usage

count_pieces(x, sep)

Arguments

x

Input string.

sep

Pattern to count for.

Value

Number of parts.

Examples

(a <- gpgr:::count_pieces("foo,bar,baz", sep = ","))
#> [1] 3
(b <- gpgr:::count_pieces("foo", sep = ","))
#> [1] 1
(k <- gpgr:::count_pieces("", sep = ","))
#> [1] 0
(m <- gpgr:::count_pieces(",", sep = ","))
#> [1] 2