Learn R Programming

pystr (version 2.0.0)

pystr_count: Count the occurrences of a substring.

Description

Return the number of non-overlapping occurrences of substring sub in the range start, end.

Usage

pystr_count(str, sub, start = 1, end = max(nchar(str)))

Arguments

str
A character vector.
sub
A character string.
start
An integer.
end
An integer.

Value

A numeric vector.

References

https://docs.python.org/3/library/stdtypes.html#str.count

Examples

Run this code
pystr_count("ababab", "aba")
pystr_count("abcxyzabc123", "abc")
pystr_count("a--b--c", "--", 4)
pystr_count(c("one", "two", "three"), "e")

Run the code above in your browser using DataLab