|
Counting Characters
Livecode is excellent at manipulating text, and this example demonstrates a nifty way to identify and count upper vs lower case characters. An example stackAll we need is a field to enter our string into and a button to call the handler which counts the number of upper and lower case characters. What our handler needs to doNow we need to decide what our function will do. Check each character: That seems simple, now lets script it in LiveCode The caseSensitive propertyIn order to identify whether a character is upper or lower case we need to set the caseSensitive property to true, by default this property is set to false. Using toLower and toUpperNow that LiveCode is case sensitive when performing text comparisons how do we check whether a character is lower or upper case? We can do this using the toLower and toUpper functions. These functions convert strings to all lower or all upperc ase letters. By converting a character to lower case and then comparing it to the original character we can identify whether it was originally lowercase or not. For example set the caseSensitive to true returns true put toUpper("a") is "a" returns false so we know the original character was lower case. The mouseUp handlerLiveCode allows you to step through each character in a string using the repeat for each control structure. This makes the process of checking each character (or word, or line, or item) very simple and straightforward. on mouseUp if toUpper(tChar) is tChar then That's it! I hope you find this a useful technique.
|
|