Case Change

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Ralph Forehand
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 42
Joined: Thu Jan 04, 2007 8:05 pm
Location: Maryland, USA

Case Change

Post by Ralph Forehand » Sat Sep 05, 2015 5:43 pm

Is there a simple way of changing Case letters in a name?

Example; change JONES to Jones
and JONES-SMITH to Jones-Smith

Thanks for any suggestions.
Ralph
"Do the right thing and everything else will take care of it's self."

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Re: Case Change

Post by andrewferguson » Sat Sep 05, 2015 5:49 pm

Hi,
The function you are looking for is the toLower. This converts all uppercase letters in a string to their lowercase equivalent. For example:

Code: Select all

put the toLower of "HELLO WORLD" --results in "hello world"
put the toLower of "Hello World" --results in "hello world"
put the toLower of "hello world" --no change as there is no uppercase characters
Andrew

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: Case Change

Post by quailcreek » Sun Sep 06, 2015 9:27 pm

Here's command I use to set the first letter of each word to caps.


Code: Select all

put fld "List" into tFldList
upCase tFldList

command UpCase @pString
   local x
   repeat with x=1 to the number of words in pString
      put upper(char 1 of word x of pString) into char 1 of word x of pString
   end repeat
   return pString
end UpCase
Tom
MacBook Pro OS Mojave 10.14

Ralph Forehand
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 42
Joined: Thu Jan 04, 2007 8:05 pm
Location: Maryland, USA

Re: Case Change

Post by Ralph Forehand » Mon Sep 07, 2015 2:31 pm

Andrew and Tom,

Thank You for your input. You were very helpful :D and as usual, this Forum is a great resource for :idea:s .

Hers's the solution I ended up with;

Code: Select all

  repeat with iy = 1 to 35  -- List with 35 Name formasts to change
   put item 2 of line iy of fld "Misc_Info" into Name1
   -- Put "JONES-SMITH" or "SMITH" into Name1 -> Change to "Jones-Smith" or "Smith"
   put tolower(Name1) into Name2  -- set all letters to lower case
   put char 1 of Name1 into char 1 of Name2  -- Capitalize 1 letter of Name
   put offset("-", Name2) into XT  -- Name includes hyphen?
   if XT > 0 then   -- Capitalize letter after hyphen
      put toUpper(char XT+1 of Name2)  into Namex
      put Namex into char xT+1 of Name2
   end if
   put Name2 into item 2 of line iy of fld "Misc_Info"
end repeat

"Do the right thing and everything else will take care of it's self."

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”