This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

StringCount

StringCount["string", "sub"]
gives a count of the number of times "sub" appears as a substring of "string".
StringCount["string", patt]
gives the number of substrings in "string" that match the general string expression patt.
StringCount["string", {patt1, patt2, ...}]
counts the number of occurrences of any of the patti.
StringCount[{s1, s2, ...}, p]
gives the list of results for each of the si.
  • The string expression patt can contain any of the objects specified in the notes for StringExpression.
  • With the default option setting Overlaps->False overlapping substrings are not treated as separate. With the setting Overlaps->True, StringCount counts substrings that overlap as separate.
  • With Overlaps->All, multiple substrings that match the same string expression are all counted as separate. With Overlaps->True, only the first such matching substring at a given position is counted as separate.
The number of occurrences of "bb" in the string "abbaabbaa":
In[1]:=
Click for copyable input
Out[1]=
 
Count the number of substrings of the form "axb" for different x characters:
In[1]:=
Click for copyable input
Out[1]=
New in 5.1