Title

Message

Confirm

Want to earn a free ClipboardFusion Pro license? We're looking for ClipboardFusion translators!
<< DiscussionsReply

Advanced title case macro

Avatar from Gravatar.com
Frank99
32 discussion posts
Hi, I'm hoping for help to write a macro sort of like "Convert Text to Title Case (Smart)" but with 2 changes:

1) expands the list of words to not capitalize to include:
a, an, and, as, at, between, but, by, down, for, from, in, into, nor, of, on, or, over, the, to, under, up, yet

2) if a colon appears (:), it is followed by one space (rather than none or more than one) and then the next word is always capitalized (i.e. even the words in the above list are capitalized)

So the string "Go Over the mountain:a journey" would become "Go over the Mountain: A Journey".

Can anyone help? Thanks!
Dec 14, 2018  • #1
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Patrick here whipped up an update to the script that should do what you're looking for. I've attached it to this reply so you can download it an import it :)

Hope that helps!
Dec 14, 2018  • #2
Avatar from Gravatar.com
Frank99
32 discussion posts
Wow, many thanks! You even nicely commented the code so I can tinker with it without learning to program.

One more request: can you do a version that will work on selected text without me having to copy it? So text that is currently selected can be corrected with one hotkey? Or, is there a way for me to do that in the program in some other way?
Dec 15, 2018  • #3
Avatar from Gravatar.com
Frank99
32 discussion posts
OK, I know I'm being a pain now, but due to a different citation system, I now also need a macro that will convert a string of text to all lower case *except* for the following, which should be uppercase:

- the first letter in the string
- the first letter after a colon
- the words "England" and "America" (I have other proper nouns also, but if you just put in these two I'm sure I can figure out how to add others)

And, as before, colons should be followed by exactly one space.

And, as stated just above, I'd like the macro to copy selected text, fix capitalization, and then paste the fixed text automatically so that I can perform this operation by selecting the text and pressing one hotkey.

I'm hoping that if you provide this, I'll be able to make any further variations on my own!

I really, really, appreciate it!
Dec 16, 2018  • #4
Keith Lammers (BFS)'s profile on WallpaperFusion.com
I've attached an update to the first one that auto-copies/pastes. Also attached a second one with your other requests.

Hope that helps!
• Attachment: Convert Text to Almost Lower Case.cfmacro [13,120 bytes]
28 days ago  • #5
Avatar from Gravatar.com
Frank99
32 discussion posts
Many thanks! But I am having problems.

With "Convert Text to Almost Lower Case",

"THIS IS MY TEST STRING:ENGLAND" becomes "THIS is my test string: ENGLAND". I'm hoping for "This is my test string: England"

And with both of the macros, when I select some words and run the macro, the macro operates on whatever was already in the clipboard--it doesn't first copy the selected words.

--Edit--

Looking at the code, there's a line commented "// Leave words after colons alone". But what you might want to do is lowercase everything, capitalize the first letter of the whole string, capitalize the first letter following the colon, and then capitalize any words on the "proper nouns" list. That way it can deal with all-lowercase and all-uppercase input in the same way.
27 days ago (modified 27 days ago)  • #6
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Try this one out :)

When I test by highlighting text in Notepad and running the macro, it replaces the text correctly. Are you running the macro with a hotkey or from the macros menu?
• Attachment: Convert Text to Almost Lower Case.cfmacro [13,256 bytes]
27 days ago  • #7
Avatar from Gravatar.com
Frank99
32 discussion posts
I was actually testing in the Macro settings window with 'Run Function', but I now realize that was a bad idea. This one works!

Two follow-up questions:

1) As mentioned, I'm not a programmer, but is there any way to use wildcards or regular expressions in the code to more easily indicate words not to capitalize? I'm thinking something like "America*" for America, American, Americas, Americans, etc.

2) If I end up with a list of words to always capitalize that is 2000 words long, is that going to impact performance substantially?
27 days ago  • #8
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Try this one out, it will now leave a word capitalized if it it contains a word on the ignore list (e.g. Americans contains America, so it will remain capitalized).

It may be a bit slower if you have thousands of words in the ignore list, but I can't imagine it would take more than a handful of seconds to run still.
• Attachment: Convert Text to Almost Lower Case.cfmacro [15,624 bytes]
27 days ago  • #9
Avatar from Gravatar.com
Frank99
32 discussion posts
I tried this with an all-lowercase "american" and it didn't capitalize it. Does it work for you?
24 days ago  • #10
Keith Lammers (BFS)'s profile on WallpaperFusion.com
It works for me, yep! What's the exact text that you're copying? These work fine for me:

  • american
  • testing this: americans
15 days ago  • #11
Avatar from Gravatar.com
Frank99
32 discussion posts
OK, it's working now. I figured out how to add spaces after ? and ! using the colon code, but I also need to remove any "." or " " (period or space) if it is the last character in the string. Can you tell me how to trim it? Thanks for the great customer service!
13 days ago  • #12
Keith Lammers (BFS)'s profile on WallpaperFusion.com
No worries! We've been swamped this week due to the holidays, but I will hopefully get a chance to look at this next week for you.
11 days ago  • #13
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, here you go. This will remove the last character if it's a period or any whitespace character:

text = Regex.Replace(text, @"[.\s]$", "");
6 days ago  • #14
Avatar from Gravatar.com
Frank99
32 discussion posts
It worked! But when I tried to add the same function to "Convert Text to Title Case (Smart with Colons)" I got a compile error. Any idea why?
5 days ago  • #15
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ah, you'll need to declare the RegEx reference at the top of the script with the other "using" statements:

using System.Text.RegularExpressions;
5 days ago  • #16
Was this helpful?  Login to Vote  Login to Vote
<< DiscussionsReply