Formula in Excel to count occurrences of substrings within strings

前端 未结 2 1916
我寻月下人不归
我寻月下人不归 2021-01-03 19:36

I am trying to count the number of times a sub-string appears within a column of string data in Excel. Please see the below example.

The column of string data (tweet

相关标签:
2条回答
  • 2021-01-03 20:28

    You are nearly there, use

    =COUNTIF(A:A, "*"&B1&"*")
    

    Caveat:
    This counts the number of cells in A:A that contain the string one or more times. It does not count the total number of instances of the string.

    0 讨论(0)
  • 2021-01-03 20:28

    A very Simple Excel Solution for occurrence of x-string ("ABC") into y-string ("ABC 123 ABC 23dfABC"):

    1. Identify length of y-string. Ly = len(y)
    2. Substitute x-string by x1-string (append only 1 char of any supported character to x-string. e.g. "ABC"=> "ABC_" ) and calculate length of new string y1-string. Ly1 = len(substitute(y,x,x1)).
    3. No of occurrence of x-string) in y-string = Ly1-Ly

    Number of Occurrence: len(substitute(y,x,x1)) - len(y)

    Nomenclature for Understanding: x-string: "ABC" x1-string: "ABC_" y-string: "ABC 123 ABC 23dfABC" y1-string: ""ABC_ 123 ABC_ 23dfABC_"

    0 讨论(0)
提交回复
热议问题