Change Case

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Mirror
Posts: 2
Joined: Thu Feb 11, 2010 4:00 am

Change Case

Post by Mirror » Fri Feb 26, 2010 1:47 am

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.

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: Change Case

Post by Regulae » Fri Feb 26, 2010 5:05 am

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

Mirror
Posts: 2
Joined: Thu Feb 11, 2010 4:00 am

Re: Change Case

Post by Mirror » Sun Feb 28, 2010 11:08 pm

Thanks Michael. Perfect.

Post Reply