Jump to content

String exemine


dugasz1

Recommended Posts

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

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
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

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...