Sachin Sachin - 18 days ago 6
Swift Question

Check if a character is lowerCase or upperCase

I am trying to make a program that stores a string in a variable called

input
.

With this
input
variable, I am then trying to convert it to an array, and then test with a for loop whether each character in the array is lowerCase or not. How can I achieve this?

I have looked at other posts relating to this question on Stack Overflow but none of the answers worked for me. I have also searched on other websites, but have been unable to find a solution, or a solution that I found was too complicated.

Here is how far I have gotten:

var input = "The quick BroWn fOX jumpS Over tHe lazY DOg"

var inputArray = Array(input)

for character in inputArray {
/*

if character is lower case {

make it uppercase

} else {

make it lowercase

}

*/
}

Answer
 var input = "The quick BroWn fOX jumpS Over tHe lazY DOg"

 var inputArray = Array(input)

 for character in inputArray {

 var strLower = "[a-z]";

 var strChar = NSString(format: "%c",character )
 let strTest = NSPredicate(format:"SELF MATCHES %@", strLower );
 if strTest .evaluateWithObject(strChar)
 {
   // lower character
 }
 else
 {
   // upper character
 }
}