ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Count occurences in string (https://www.excelbanter.com/excel-discussion-misc-queries/233475-count-occurences-string.html)

Ken

Count occurences in string
 
This should be very simple, but I don't see how to do it without a macro:
How do you count the number of hyphens (for example) in a string?

abc-de-a32-ej2-wkjew-w should give 5
we2-232if should give 1
wekjf2 should give 0


Jacob Skaria

Count occurences in string
 
The below formula will do.

=LEN(A1)-LEN(SUBSTITUTE(A1,"-",))

If this post helps click Yes
---------------
Jacob Skaria


"Ken" wrote:

This should be very simple, but I don't see how to do it without a macro:
How do you count the number of hyphens (for example) in a string?

abc-de-a32-ej2-wkjew-w should give 5
we2-232if should give 1
wekjf2 should give 0


Ron Rosenfeld

Count occurences in string
 
On Wed, 10 Jun 2009 11:55:02 -0700, Ken wrote:

This should be very simple, but I don't see how to do it without a macro:
How do you count the number of hyphens (for example) in a string?

abc-de-a32-ej2-wkjew-w should give 5
we2-232if should give 1
wekjf2 should give 0


=len(str)-len(substitute(str,"-","")

--ron

Ken

Count occurences in string
 
Ah ... of course. Thank you both.

Ken

This should be very simple, but I don't see how to do it without a macro:
How do you count the number of hyphens (for example) in a string?

abc-de-a32-ej2-wkjew-w should give 5
we2-232if should give 1
wekjf2 should give 0


=len(str)-len(substitute(str,"-","")

--ron



All times are GMT +1. The time now is 08:00 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com