views:

27

answers:

2

Is there anything out there for a conditional capitalize type function? I want to capitalize a string only if I detect there are a certain percentage of capitals letters. I want to do this because I don't want to run the function on everything, but I do want to run it on strings that I think are written in all caps.

Or I guess is there a way to return how many letters string.downcase does work on?

Thanks!

A: 

No, but there is nothing preventing you from putting the call to titleize inside a conditional that checks for the case you're interested in.

Chuck
A: 

Ah ok I think I got it.

string.count('A-Z')/string.length
james