Page 1 of 1

Messing around with capital letters.

Posted: Sat Apr 21, 2018 6:26 pm
by richmond62
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 197 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

Re: Messing around with capital letters.

Posted: Sat Apr 21, 2018 6:33 pm
by richmond62
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.

Re: Messing around with capital letters.

Posted: Sat Apr 21, 2018 6:56 pm
by bogs
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:

Re: Messing around with capital letters.

Posted: Sun Apr 22, 2018 10:08 am
by richmond62
Pretty infantile, but notwithstanding:
headcase.png
HCASE.livecode.zip
Here's the stack.
(9.62 KiB) Downloaded 196 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

Re: Messing around with capital letters.

Posted: Sun Apr 22, 2018 10:32 am
by richmond62
wp.png

Re: Messing around with capital letters.

Posted: Sun Apr 22, 2018 12:57 pm
by bogs
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.

Re: Messing around with capital letters.

Posted: Sun Apr 22, 2018 8:02 pm
by jacque
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.