Let's say cell A1 contains the phrase "Hello, world" and you want to
count the number of "o"s, you can enter this formula in cell B1:

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

I find this a bit of a hack, but it works. It gets kind of messy when
you want to count more than one letter.  For example, let's say you
have some DNA sequence in A1 and you want to calculate the GC%:

=(LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(UPPER(A1),"G",""),"C","")))/LEN(A1)

Again, it works, but it's rather ugly.  It gets worse if I want to
know how many non-GCTA characters there are in a sequence.

Ruby has a rather elegant way to do this using regular expressions
(perl has a similar way):

print A1.gsub(/[GCTA]/i,"").length

Anyone know of a cleaner way to count the number of characters within OOo Calc?

Regards,
- Robert

--~--~---------~--~----~------------~-------~--~----~
Central West End Linux Users Group (via Google Groups)
Main page: http://www.cwelug.org
To post: [email protected]
To subscribe: [email protected]
To unsubscribe: [email protected]
More options: http://groups.google.com/group/cwelug
-~----------~----~----~----~------~----~------~--~---

Reply via email to