Marco Bortolotto
Marco Bortolotto

Reputation: 3

Counting string sequence inside a cell

I have a string such as "0000xxx0xxx0xx00xxxxxx0xx0xxxxx" in an Excel Cell

I want to count how many times a sequence of more than three "x" appears, in other words, how many times a sequence such as "xxx" or "xxxx" and so on appears in this cell.

The output would be 4 times for this example.

Upvotes: 0

Views: 122

Answers (2)

JvdV
JvdV

Reputation: 75840

For the sake of alternatives:

=COUNTA(FILTERXML("<t><s>"&SUBSTITUTE(A1,"0","</s><s>")&"</s></t>","//s[string-length(.)>2]"))

enter image description here

FILTERXML is available from Excel 2013 onwards (except Excel Online and Excel for Mac).

Upvotes: 3

Scott Craner
Scott Craner

Reputation: 152450

use:

=(LEN("0"&A1)-LEN(SUBSTITUTE("0"&A1,"0xxx","0")))/3

enter image description here

Upvotes: 4

Related Questions