Page 1 of 1

Change Case

Posted: Fri Feb 26, 2010 1:47 am
by Mirror
Hi, I am a newbie to Rev, I am making a simple stack with some text fields displaying data. Some of they information in the fields in is in the wrong "sentence case". I have found a way to change this automatically using the property inspector of the field (i.e. in the property inspector - "Text Formatting" Tab - "Change Case" button at the bottom - then I can choose to have it in ALL CAPS, all lowercase, Sentence case, or Title Case (which I want)). I


My question is, is there any way of doing this in scripting? I am sure there must be, but through my searches of the dictionary I cannot find the right property name to do this. Can anyone help out? Thanks for any help.

Re: Change Case

Posted: Fri Feb 26, 2010 5:05 am
by Regulae
Useful functions are toUpper and toLower. To change the first character of a sentence in, for example, card field “test”, you could script:

Code: Select all

put toUpper(char 1 of card field "test") into char 1 of card field "Test"
To script title case, you could use:

Code: Select all

put line 1 of card field "test" into originalTitle
repeat for each word w in originalTitle
   put toUpper(char 1 of w) into char 1 of w
   put w&space after newTitle
 end repeat
 delete the last char in newTitle
 put newTitle into line 2 of card field "test"
This converts anything on line 1 to title case on line 2. It is coded this way for clarity- the “repeat” goes through originalTitle word by word, replacing the first character with its capital equivalent. We use this to build newTitle. newTitle will have an extra space on the end, which we remove.

Regards,

Michael

Re: Change Case

Posted: Sun Feb 28, 2010 11:08 pm
by Mirror
Thanks Michael. Perfect.