Script Example: Case Changer

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Script Example: Case Changer

Post by CyberCitizen » Fri May 31, 2013 8:56 am

Quick little script I knocked up while bored at work, hopefully someone finds it useful. Please note it does not follow standards in regards to Title Case, it just replaces any letter that follows a space with the upper case version of that letter.

Similar to JRL's Example Posted Here: http://www.mjtnet.com/usergroup/title-case-t7736.html

Image

Code: Select all

Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1

ExtractFileName>Command_Line,strFileName
ExtractFileExt>Command_Line,strExt
StringReplace>%strFileName%,",,strFileName
StringReplace>%strExt%,",,strExt
StringReplace>%strFileName%,%strExt%,,strFileName
Trim>%strFileName%,strFileName
Let>APP_TITLE=%strFileName%

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 96
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'Case Changer'
  ClientHeight = 212
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = False
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 8
    Width = 64
    Height = 13
    Caption = 'Convert Case'
  end
  object MSMemo1: tMSMemo
    Left = 8
    Top = 24
    Width = 457
    Height = 153
    WantTabs = True
    WordWrap = True
    ScrollBars = ssVertical
    ScrollBarsAutoShowing = ssVertical
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 8
    Top = 184
    Width = 121
    Height = 25
    Caption = 'UPPERCASE'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 177
    Top = 184
    Width = 121
    Height = 25
    Caption = 'lowercase'
    TabOrder = 2
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton3: tMSButton
    Left = 344
    Top = 184
    Width = 121
    Height = 25
    Caption = 'Titlecase'
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

SetDialogProperty>Dialog1,,Caption,%APP_TITLE%
AddDialogHandler>Dialog1,MSButton1,OnClick,sUpperCase
AddDialogHandler>Dialog1,MSButton2,OnClick,sLowerCase
AddDialogHandler>Dialog1,MSButton3,OnClick,sTitleCase

Show>Dialog1,dResult

If>%dResult%=2,Exit

SRT>sUpperCase
  GetDialogProperty>Dialog1,MSMemo1,Text,vTxtString
  UpperCase>%vTxtString%,vTxtString
  SetDialogProperty>Dialog1,MSMemo1,Text,%vTxtString%
END>sUpperCase

SRT>sLowerCase
  GetDialogProperty>Dialog1,MSMemo1,Text,vTxtString
  LowerCase>%vTxtString%,vTxtString
  SetDialogProperty>Dialog1,MSMemo1,Text,%vTxtString%
END>sLowerCase

SRT>sTitleCase
  GetDialogProperty>Dialog1,MSMemo1,Text,vTxtString
  LowerCase>%vTxtString%,vTxtString
  StringReplace>%vTxtString%,%vTxtString%, %vTxtString%,vTxtString
  StringReplace>%vTxtString%, a, A,vTxtString
  StringReplace>%vTxtString%, b, B,vTxtString
  StringReplace>%vTxtString%, c, C,vTxtString
  StringReplace>%vTxtString%, d, D,vTxtString
  StringReplace>%vTxtString%, e, E,vTxtString
  StringReplace>%vTxtString%, f, F,vTxtString
  StringReplace>%vTxtString%, g, G,vTxtString
  StringReplace>%vTxtString%, h, H,vTxtString
  StringReplace>%vTxtString%, i, I,vTxtString
  StringReplace>%vTxtString%, j, J,vTxtString
  StringReplace>%vTxtString%, k, K,vTxtString
  StringReplace>%vTxtString%, l, L,vTxtString
  StringReplace>%vTxtString%, m, M,vTxtString
  StringReplace>%vTxtString%, n, N,vTxtString
  StringReplace>%vTxtString%, o, O,vTxtString
  StringReplace>%vTxtString%, p, P,vTxtString
  StringReplace>%vTxtString%, q, Q,vTxtString
  StringReplace>%vTxtString%, r, R,vTxtString
  StringReplace>%vTxtString%, s, S,vTxtString
  StringReplace>%vTxtString%, t, T,vTxtString
  StringReplace>%vTxtString%, u, U,vTxtString
  StringReplace>%vTxtString%, v, V,vTxtString
  StringReplace>%vTxtString%, w, W,vTxtString
  StringReplace>%vTxtString%, x, X,vTxtString
  StringReplace>%vTxtString%, y, Y,vTxtString
  StringReplace>%vTxtString%, z, Z,vTxtString
  StringReplace>%vTxtString%,%LF%a,%LF%A,vTxtString
  StringReplace>%vTxtString%,%LF%b,%LF%B,vTxtString
  StringReplace>%vTxtString%,%LF%c,%LF%C,vTxtString
  StringReplace>%vTxtString%,%LF%d,%LF%D,vTxtString
  StringReplace>%vTxtString%,%LF%e,%LF%E,vTxtString
  StringReplace>%vTxtString%,%LF%f,%LF%F,vTxtString
  StringReplace>%vTxtString%,%LF%g,%LF%G,vTxtString
  StringReplace>%vTxtString%,%LF%h,%LF%H,vTxtString
  StringReplace>%vTxtString%,%LF%i,%LF%I,vTxtString
  StringReplace>%vTxtString%,%LF%j,%LF%J,vTxtString
  StringReplace>%vTxtString%,%LF%k,%LF%K,vTxtString
  StringReplace>%vTxtString%,%LF%l,%LF%L,vTxtString
  StringReplace>%vTxtString%,%LF%m,%LF%M,vTxtString
  StringReplace>%vTxtString%,%LF%n,%LF%N,vTxtString
  StringReplace>%vTxtString%,%LF%o,%LF%O,vTxtString
  StringReplace>%vTxtString%,%LF%p,%LF%P,vTxtString
  StringReplace>%vTxtString%,%LF%q,%LF%Q,vTxtString
  StringReplace>%vTxtString%,%LF%r,%LF%R,vTxtString
  StringReplace>%vTxtString%,%LF%s,%LF%S,vTxtString
  StringReplace>%vTxtString%,%LF%t,%LF%T,vTxtString
  StringReplace>%vTxtString%,%LF%u,%LF%U,vTxtString
  StringReplace>%vTxtString%,%LF%v,%LF%V,vTxtString
  StringReplace>%vTxtString%,%LF%w,%LF%W,vTxtString
  StringReplace>%vTxtString%,%LF%x,%LF%X,vTxtString
  StringReplace>%vTxtString%,%LF%y,%LF%Y,vTxtString
  StringReplace>%vTxtString%,%LF%z,%LF%Z,vTxtString
  Trim>%vTxtString%,vTxtString
  SetDialogProperty>Dialog1,MSMemo1,Text,%vTxtString%
END>sTitleCase

Label>Exit
FIREFIGHTER

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Fri May 31, 2013 11:16 pm

That's pretty useful. I've just saved this one, too. I often have to perform this kind of task.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Sat Jun 08, 2013 12:55 am

I love this part of my job....

Image

Aah, who am I kidding, I love all parts of my job. :D

Well done CyberCitizem. I'll go and post an announcement thread now.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Sat Jun 08, 2013 1:42 am

Thank you Parsnipnose3000.

Had a shocking sleep last night, however this was some good news to wake up to.

Have to start writing some more now, and finish that FTP script as soon as I get some more time.
FIREFIGHTER

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sun Jun 09, 2013 12:11 pm

Hi CyberCitzen,
CyberCitizen wrote: Had a shocking sleep last night, however this was some good news to wake up to.
Have to start writing some more now, and finish that FTP script as soon as I get some more time.
Congrats!
BTW, have you considered using regex?

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Sun Jun 09, 2013 11:51 pm

I really don't know RegEx, that's the next thing to teach myself.
FIREFIGHTER

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Jun 10, 2013 12:50 am

CyberCitizen wrote:I really don't know RegEx, that's the next thing to teach myself.
Thanks for your candid feedback. RegexBuddy could be handy to speed up regex learning.
Again, CyberCitizen, appreciate your generous sharing of your many practically useful scripts with us.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Tue Jun 11, 2013 11:22 pm

Thanks for the Regex link, Armsys. The only regex I've used to far has been stripped from the examples Marcus posted.

It's ridiculously powerful though.
Yes, we have a Custom Scripting Service. Message me or go here

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jun 11, 2013 11:29 pm

Parsnipnose3000 wrote:Thanks for the Regex link, Armsys. The only regex I've used to far has been stripped from the examples Marcus posted.
Appreicate your encouraging feedback. Let's make Macro Scheduler a viable tool for promoting peaceful humanity.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Tue Jun 11, 2013 11:44 pm

Easypatterns makes Regex a lot more accessible, too.

To search for a URL

Code: Select all

// Find URLS
RegEx>[Hyperlink],textorvariabletosearch,1,matches,num,0
The Easy Patterns reference is a very interesting read.
Yes, we have a Custom Scripting Service. Message me or go here

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Jun 11, 2013 11:52 pm

Parsnipnose3000 wrote:Easypatterns makes Regex a lot more accessible, too.
I find your sample code very persuasive. Perhaps I should give myself a second chance to revisit and relearn the EasyPatterns.
My previous argument: If EasyPatterns will be retranslated into PCRE anyway (runtime efficiency loss) and additional learning curve on top amongst PCRE, Perl, VBScript, JavaScript....etc, it isn't worth of my effort.
Thanks for salvaging my lost hope in EasyPatterns.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Fri Jun 14, 2013 11:46 pm

It's great for people like me who haven't really delved into Regex too much. I really need to though, because the more I can answer myself and the less I have to defer to Marcus, the better. :)
Yes, we have a Custom Scripting Service. Message me or go here

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Jun 15, 2013 1:12 am

Parsnipnose3000 wrote:...the more I can answer myself and the less I have to defer to Marcus, the better. :)
Are you a contractor of MJT? May I apply for the job?

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts