I’d like to let a string change letters to lowercase or uppercase randomly(in Xcode).
for example: “example” to “ExaMpLe” or “eXAMPle” or ExAmPlE” or something else like this randomly..
hot can i solve this?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
NSStringhas both alowercaseStringanduppercaseStringmethod. You can iterate over the characters in a string as a sequence of substrings, using some random source to call the appropriate lower/upper case on each of them, collecting the result. Something like…You may prefer a better source of entropy than
rand, but it’ll do for an example (don’t forget to seed it if you use this case as is). If the strings are large, you can do it in-place on anNSMutableString.