count_pieces: Count Number of Parts in a String

View source: R/sv.R

count_piecesR Documentation

Count Number of Parts in a String

Description

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 = ","))
(b <- gpgr:::count_pieces("foo", sep = ","))
(k <- gpgr:::count_pieces("", sep = ","))
(m <- gpgr:::count_pieces(",", sep = ","))

umccr/gpgr documentation built on April 21, 2024, 1:16 a.m.