blog | python

Count Number of Occurrences of Certain Character in String in R

library(stringr)

# declaring string
str1 = "$geeks%for!geeks%"

# declaring character to find
ch1 = "a"
print("Count for character a")
str_count(str1,ch1)

ch2 = "%"
print("Count for character %")
str_count(str1,ch2)

Example 2:

library(stringr)

# declaring string
str = c("$geeks%for!geeks%","cs^e%portal",
		"le%..e3oten","joinnow3")
print ("Original vector")
print (str)

# declaring character to find
ch2 = "%"
print("Count for character %")
str_count(str,ch2)

Similar Posts:

    None Found

Leave a Reply

Your email address will not be published. Required fields are marked *