0
votes

I would like to count the number of occurances of a string within a single cell in Google Sheets.

If I have

599^612
600
601^602^604
44^56^71^83^95^107^119^131^402^451^466^478^490^502^514^571^633^648^661^680^746^813^878^945^1010^1069^1100^1131^1161^1226^1247^1258

I would like to get the counts of ^ in each row.

Cell | Count
599^612 | 2
600 | 1
601^602^604 | 3
44^56^71^83^95^107^119^131^402 | 9

I have tried find, count and countif but can't work it out. Also reviewed Count the number occurrences of a character in a string but need a solution in Google Sheets.

3

3 Answers

2
votes

use:

=INDEX(IF(A1:A="",,LEN(REGEXREPLACE(""&A1:A, "[0-9]", ))+1))

enter image description here

2
votes

This can easily be done using the LEN and SUBSTITUTE functions.

=LEN(A2)-LEN(SUBSTITUTE(A2, "^", ""))+1
1
votes

I'm not sure why 44^56^71^83^95^107^119^131^402^451^466^478^490^502^514^571^633^648^661^680^746^813^878^945^1010^1069^1100^1131^1161^1226^1247^1258 cuts off at 44^56^71^83^95^107^119^131^402, but you could count ^ like this:

=arrayformula({A1:A,if(A1:A<>"",iferror(len(regexreplace(A1:A,"[^\^]",""))+1,),)})

enter image description here

Or just the count:

=arrayformula(if(A1:A<>"",iferror(len(regexreplace(A1:A,"[^\^]",""))+1,),))