Messing around with capital letters.

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
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Messing around with capital letters.

Post by richmond62 » Sat Apr 21, 2018 6:26 pm

This is pursuant to a current discussion on the Use-List about
capitalising words in titles.
titler.png
TITLER.livecode.zip
(6.34 KiB) Downloaded 147 times
Code in the button "SORT THINGS OUT":

Code: Select all

on mouseUp
   put empty into fld "fCOOKED"
   put fld "fRAW" into cRAW
   put 1 into KOUNT
   repeat until cRAW is empty
      put word 1 of cRAW into rWORD
      put 1 into QOUNT
      repeat until line QOUNT of fld "fRW" is empty
         put line QOUNT of fld "fRW" into VOX
         if rWORD = VOX then
         put rWORD & numToCodePoint(32) after fld "fCOOKED"
         delete word 1 of cRAW
         put 33 into xPASS
      end if
      add 1 to QOUNT
      end repeat
      if xPASS = 33 then
         -- do nothing
         else
  put toUpper (char 1 of rWORD) into cC
      delete char 1 of rWORD
      put (cC & rWORD) into cWORD
      delete word 1 of cRAW
      put cWORD & numToCodePoint(32) after fld "fCOOKED"
      end if
      add 1 to KOUNT
      put KOUNT
      put 0 into xPASS
   end repeat
end mouseUp

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Messing around with capital letters.

Post by richmond62 » Sat Apr 21, 2018 6:33 pm

I know this will come across as extremely "stuffy" and "conservative",
but I think that children who are being taught programming should
also be "dragged" through a bit of text manipulation instead of just
games, games and games.

Certainly, last Summer the children I taught some BBC BASIC and LiveCode to
did not object, and some said they found it interesting.

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Messing around with capital letters.

Post by bogs » Sat Apr 21, 2018 6:56 pm

richmond62 wrote:
Sat Apr 21, 2018 6:33 pm
I know this will come across as extremely "stuffy" and "conservative"
That probably depends on whether your talking to children or not, to me it sounds pretty logical. Of course, I am old, stuffy, and more than a little conservative... :wink:
Image

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Messing around with capital letters.

Post by richmond62 » Sun Apr 22, 2018 10:08 am

Pretty infantile, but notwithstanding:
headcase.png
HCASE.livecode.zip
Here's the stack.
(9.62 KiB) Downloaded 145 times

Code: Select all

on mouseUp
   if the selectedText is not empty then
      put toLower(the selectedText) into UPP
      replace the selectedText with UPP in fld "ff"
   end if
end mouseUp

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Messing around with capital letters.

Post by richmond62 » Sun Apr 22, 2018 10:32 am

wp.png

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Messing around with capital letters.

Post by bogs » Sun Apr 22, 2018 12:57 pm

Making a word processor was actually the first tutorial I ever completed in Delphi, I think that is a great place to start. Delphi's tutorial was somewhere between Notepad and Word in completeness.
Image

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Messing around with capital letters.

Post by jacque » Sun Apr 22, 2018 8:02 pm

richmond62 wrote:
Sat Apr 21, 2018 6:26 pm
Code in the button "SORT THINGS OUT":
If I understand it, you want to title-case a line, omitting some reserved words. I'd do it like this, which is faster and doesn't thrash the CPU as much:

Code: Select all

on titleCase
  put fld "omittedWords" into tOmitted
  put fld "fRaw" into tText
  put toLower(tText) into tText
  repeat with x = 1 to the number of words in tText
    if trueword x of tText is among the lines of tOmitted then next repeat
    put toUpper(char 1 of word x of tText) into char 1 of word x of tText
  end repeat
  put tText into fld "fCooked"
end titleCase
This is suitable for titles, which are usually short. If you want to special-case longer text, using "repeat for each..." and putting the revised text after a new variable is faster. You'd also need to account for line breaks.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”