3D Clipboard

A place to discuss 3D Clipboard

Title Caps

Share actions you've created here.
Bill
Posts: 4
Joined: Tue Mar 19, 2013 4:52 pm

Title Caps

Postby Bill » Sun May 08, 2016 5:12 pm

I recently had to convert a lot of lines of text to appear like titles, i.e. the first letter of each work needed to be capitalized. Since it is more fun to write code than to mindlessly delete characters and replace them with Caps, I wrote the following code. It isn't terribly smart. Minor words like "a", "the", "by" are capitalized even though they aren't in a "real" title. Also, subsequent letters in a word that are capitalized, are left that way.
In Any Case, You May Find THiS Useful.

Code: Select all

' Action: Title Case
' Author: Bill King
' Date:   05-07-16
' Code:   VBscript
'
' This code makes sure the first letter of each word is capitalized like a title;
' Even minor words such as "a", "the", "by", etc. will be made upper case.
' Capitalized letters in the middle of a word will remain capitalized
'
' This works for Ascii characters
' lower case letters have an ascii value from 97 to 122
' Upper case letters have an ascii value from 65 to 90
'
' B. King
'
Tcase1 = ""
strCBI = clipboard.value
intlencbi = len(strcbi)
CapThis = 1                                   ' 1 - cap the current letter; 2 - leave the letter alone
                                              ' the first character should be capitalized If it is a letter
For Indx = 1 To intlencbi
   ch = Asc(Mid(strCBI, Indx, 1))             ' get the decimal value of the current letter in the string
   If ch = 32 then CapThis = 1                ' the next character should be capitalized If it is a letter
   If ch <> 32 then
      If CapThis = 1 then                     ' If the CapThis flag isn't set, don't do anything with the character
         If ((ch > 96) and (ch < 123)) Then   ' we only need to consider lower case characters
           ch = ch - 32                      ' change ascii value to upper case
          CapThis = 0                       ' turn off the CapThis flag
         end if
         CapThis = 0                          ' turn off the CapThis flag
      End If
   End If
   Tcase1 = Tcase1 & Chr(ch)                  ' Keep building the new string with changed cases
Next
'
clipboard.value = TCase1


Return to “Actions”

 

 

cron