I needed to detect a mixed case string in classic ASP. I define a mixed case string as containing both upper and lower case characters, like AuxagGsrLpa. I could not find a free function on the web to make this decision, so I wrote one.
<% Function isMixedCase( str ) 'detects mixed case strings using the english alphabet 'ignores spaces and other non-alphabetic characters str = trim( str ) isMixed = false lastCase = "" for i=1 to len( str ) currentChar = mid( str, i, 1 ) if asc( currentChar ) >= 65 and asc( currentChar ) <= 90 then if lastCase <> "" and lastCase <> "upper" then isMixed = true exit for else lastCase = "upper" end if else if asc( currentChar ) >= 97 and asc( currentChar ) <= 122 then 'lower if lastCase <> "" and lastCase <> "lower" then isMixed = true exit for else lastCase = "lower" end if else lastCase = "" end if end if next if isMixed then isMixedCase = true else isMixedCase = false end if End Function %>
Here are a few test strings to demonstrate the functionality:
<%
response.write "Hello " & isMixedCase( "Hello " ) & " <br>"
response.write "hello! " & isMixedCase( "hello!" ) & " <br>"
response.write "HELLO " & isMixedCase( "HELLO " ) & " <br>"
response.write "hello there " & isMixedCase( "hello there" ) & " <br>"
response.write "hellothere " & isMixedCase( "hellothere" ) & " <br>"
response.write "hellotherE " & isMixedCase( "hellotherE" ) & " <br>"
%>
Here is the resulting HTML output of the tests:
Hello True
hello! False
HELLO False
hello there False
hellothere False
hellotherE True