Jump to content

Capitals detection


.:HyPeX:.

Recommended Posts

Well you can use this to get the uppercase letters.

Should work, tested on Lua demo.

function getUppercaseLetters(string) 
 local wow = "" 
 for i=0,string.len(string) do -- Do for each letter 
  local string_ = string.sub(string, i, i) -- Get the letter 
  if(string.find(string_, "%u")) then -- Check if it's uppercase 
   wow = wow .. string_ -- Add to result 
  end 
 end 
 return wow -- Return the uppercase string 
end 

So in action it would probably be like:

addEventHandler("onPlayerChat", root, -- When someone says something 
 function(message, messageType) 
  if(getUppercaseLetters(message) ~= "") then -- If there are any uppercase strings 
   outputDebugString("Used uppercase letters: '" .. getUppercaseLetters(message) .. "'.") -- Print a message 
  end 
 end 
) 
  

Edited by Guest
Link to comment
by the way, where i can find those variables of the find? there you used "%u", where i can find all the values lua has? i couldnt find them on the lua reference manual (wich is linked from here).

Found the %u thingy here »

I did know most of those before too, but then I was wondering what other ones there are.

Link to comment
You need to improve some aspects in your function, namely variables (local variables are recommended) and concatenation (table concatenation is faster).

Even though concatenation is easy to do, I suppose we're not talking about long paragraphs, so I doubt the speed is a common factor for his use. Changed to local variables as suggested.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...