- Mon Feb 14, 2011 10:16 am
#2264
We had a small discussion about detecting upper case in chat strings etc, here is an example of how you could do that with regex and php (i leave it to you to discover the correct functions in java)
Code: Select all
<?php
$chatstring='I\'ll tell you what I want, WHAT I REALLY REALLY WANT!';
$alllettersregex='/\w/';
$lowercaseregex='/[a-z]/';
$uppercaseregex='/[A-Z]/';
$lettercount=preg_match_all($alllettersregex,$chatstring,$letterarray);
$uppercount=preg_match_all($uppercaseregex,$chatstring,$upperarray);
$lowercount=preg_match_all($lowercaseregex,$chatstring,$lowerarray);
$percentupper=(($uppercount/$lettercount)*100);
echo "String is $percentupper percent upper case";
?>