StrCountW.Rd
Count the number of words that appear within a character string.
StrCountW(x)
This is just a wrapper for a fine regexpr. It uses the expression \b\W+\b
to separate the
words. The code \W
is equivalent to [^[:alnum:]_])
wheras [:alnum:]
contains [:alpha:]
and [:digit:]
.
So everything that is not an alphanumeric character, a digit or a _ (underscore) is used as separator for the words to be counted.
an integer defining the number of word in the string
StrCountW("This is a true story!")
#> [1] 5
StrCountW("Just_one_word")
#> [1] 1
StrCountW("Not-just.one/word")
#> [1] 4
StrCountW("And what about numbers 8899 or special characters $$$/*?")
#> [1] 8
StrCountW(" Starting'n ending with some whitespace ")
#> [1] 6
StrCountW(c("This is a", "text in more", "than one line."))
#> [1] 3 3 3