Bluepoint Design

Practical Cost-Effective Solutions
Case Conversion - Title

Home
Up
This sample macro demonstrates how to run thru a string of text evaluating one character at a time to do something. In this case we're changing the case from whatever to Title Case. In order to simplify the evaluations and conversion and avoid having a huge lookup table I evaluate and convert them mathematically using their ASCII values. Click here for an explanation of ASCII.

Start by getting the %length% of the text and use that for the number of repeats. Then with each iteration store the the iteration in %position%. In each iteration copy one character at %position% and store it in %char%. Now test if it's a space and trip the Boolean var %space%. If it's a space simply append that character to %result% and skip the rest. This is the trigger for the next iteration. On the next iteration you test to see if the last one was a space and if it is see if the character is a lower case letter. Do this by getting the ASCII value and if it's greater than or equal to 97 and less than or equal to 122 it's a lower case letter. In ASCII lower "a" is 97 and z is 122. If that's the case subtract 32, upper A is 65 thus the difference, to get the upper case equivalent. Now convert back to a letter and write to %char% flip the space Boolean var back off. In each iteration you simply append to %result% and move on.

CaseConvert-Title.mex

Page last updated: 06/24/2009

 
Practical Cost-Effective Solutions