Post any ideas / suggestions for the game servers here.
  • User avatar
By gl1tch
#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";

?>
User avatar
By Sharingan616
#2415
Code: Select all
public class UpperCasePercent{
  public static void main(String[] args){
    
    String playertext = "Why did the chicken cross the road? TELL ME WHY THE CHICKEN CROSSED THE ROAD!";
    int upperCaseCount = 0;
    char letter;
    
    for (int i = 0; i < playertext.length(); i++)
    {
      letter = playertext.charAt(i);
      if(Character.isUpperCase(letter))
        upperCaseCount ++;
    }
    
    double percentage = ((upperCaseCount*100)/playertext.length());
    System.out.println(percentage+"%");
    
  }
}
This code returns 44.0%.

:D
User avatar
By Sharingan616
#2422
The code returns 44% because technically the string is 44% uppercase and 56% lowercase, just normal spaces, and other punctuation.
Code: Select all
public class UpperCasePercent{
  public static void main(String[] args){
    
    String playertext = "Why did the chicken cross the road? TELL ME WHY THE CHICKEN CROSSED THE ROAD!";
    int upperCaseCount = 0;
    int lowerCaseCount = 0;
    char letter;
    
    for (int i = 0; i < playertext.length(); i++)
    {
      letter = playertext.charAt(i);
      if(Character.isUpperCase(letter))
        upperCaseCount ++;
      if(Character.isLowerCase(letter))
        lowerCaseCount ++;
    }
    
    int upperpercentage = ((upperCaseCount*100)/playertext.length());
    int lowerpercentage = ((lowerCaseCount*100)/playertext.length());
    System.out.print("The string is "+upperpercentage+"% uppercase and ");
    System.out.println(lowerpercentage+"% lowercase.");
  }
}
This code prints this:
"The string is 44% uppercase and 35% lowercase."

Then I guess you could write if the uppercase percentage is greater then the lowercase percentage, kick the person typing or kick them if they do it 5 in a row or something.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]