dugasz1 Posted May 31, 2013 Share Posted May 31, 2013 Hy! I want to exemine a string. Requirement: - Start whit capital word - Only letters are avaible - Special characters are unavaible Can someone send me some example to i can made it? Link to comment
Castillo Posted May 31, 2013 Share Posted May 31, 2013 I recently posted a function to check if a string's first letter is uppercase: viewtopic.php?f=91&t=59657 Link to comment
dugasz1 Posted June 3, 2013 Author Share Posted June 3, 2013 Thank you, But i wanna check all the space after start whit capital letter too. Now he can write: Sean devlin or Sean jr. devlin but it isn't good Every first letter after space must capital letter : Sean Devlin or Sean Jr. Devlin And the special char problem. Can you write me a example for check a edit for special characters. Link to comment
Castillo Posted June 3, 2013 Share Posted June 3, 2013 function hasStringCharacters ( str ) return str:find ( "%p" ) end Link to comment
dugasz1 Posted June 4, 2013 Author Share Posted June 4, 2013 hmmm Sorry i don't understand what is it do? Link to comment
Castillo Posted June 4, 2013 Share Posted June 4, 2013 It's a function to check if a string has characters or not. Link to comment
dugasz1 Posted June 4, 2013 Author Share Posted June 4, 2013 ohh and how can i check after space start whit capital word? Link to comment
Castillo Posted June 4, 2013 Share Posted June 4, 2013 Split the string by spaces, then for each sub-string, check if it has capital letter using the function I gave you. Link to comment
dugasz1 Posted June 8, 2013 Author Share Posted June 8, 2013 Now i can exemine after the first space the letter but i can't exemine more space How can i exemine after all space and if all caputal letter return whit true if 1 or more after space letter isn't capital the return false. function capitalAfterSpace ( str ) s,e = string.find(str,"%s") outputChatBox("kezd"..s.." "..e) afterSpace = string.sub(str,s+1,e+1) --outputChatBox(afterSpace) return (afterSpace == afterSpace:upper () ) end function chat() -- test outputChatBox(tostring(capitalAfterSpace("Test Test"))) -- return whit true outputChatBox(tostring(capitalAfterSpace("Test test"))) -- return whit false outputChatBox(tostring(capitalAfterSpace("Test Test Test"))) -- return whit true outputChatBox(tostring(capitalAfterSpace("Test Test test"))) -- return whit true end addCommandHandler("a",chat) Link to comment
Castillo Posted June 9, 2013 Share Posted June 9, 2013 function capitalAfterSpace ( str ) local splitted = split ( str, " " ) local total = #splitted local found = 0 local index = 1 while splitted [ index ] do if isStringFirstLetterUppercase ( splitted [ index ] ) then found = ( found + 1 ) end index = ( index + 1 ) end return ( total == found ) end function isStringFirstLetterUppercase ( str ) local letter = str:sub ( 1, 1 ) return ( letter:upper ( ) == letter ) end outputChatBox ( tostring ( capitalAfterSpace ( "Test Test" ) ) ) -- returns: true outputChatBox ( tostring ( capitalAfterSpace ( "Test test" ) ) ) -- returns: false outputChatBox ( tostring ( capitalAfterSpace ( "Test Test Test" ) ) ) -- returns: true outputChatBox ( tostring ( capitalAfterSpace ( "Test Test test" ) ) ) -- returns: false Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now