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
35 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
35 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
35 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]
Dec 18, 2018  • #5
Avatar from Gravatar.com
Frank99
35 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.
Dec 19, 2018 (modified Dec 19, 2018)  • #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]
Dec 19, 2018  • #7
Avatar from Gravatar.com
Frank99
35 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?
Dec 19, 2018  • #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]
Dec 19, 2018  • #9
Avatar from Gravatar.com
Frank99
35 discussion posts
I tried this with an all-lowercase "american" and it didn't capitalize it. Does it work for you?
Dec 22, 2018  • #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
Dec 31, 2018  • #11
Avatar from Gravatar.com
Frank99
35 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!
Jan 2, 2019  • #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.
Jan 4, 2019  • #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]$", "");
Jan 9, 2019  • #14
Avatar from Gravatar.com
Frank99
35 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?
Jan 10, 2019  • #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;
Jan 10, 2019  • #16
Avatar from Gravatar.com
Frank99
35 discussion posts
I'm back with 2 more improvement requests.

First, can this be modified to ignore any leading non-alphabetic characters and capitalize the first alphabetic character? So running it on:

5. this is the title
or
- my first bullet point

would produce

5. This is the title
and
- My first bullet point

Second, can this be modified to treat every line as a separate instance to be capitalized? So I could highlight the entirety of:

- title one
- title two
- title three

And in one keystroke get:

- Title one
- Title two
- Title three

Thanks!
20 days ago  • #17
Keith Lammers (BFS)'s profile on WallpaperFusion.com
It should be possible, I will have a look at it when I get a chance. It might not be until next week though.
16 days ago  • #18
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Alrighty, I'm sure the script is messy and can probably be done a bit better, but this should at least work
9 days ago  • #19
Avatar from Gravatar.com
Frank99
35 discussion posts
Thanks again! I have it basically working and even modified it to deal with question marks etc. in addition to just the colon. One problem is that after running the macro on text, it leaves the cursor on the next line after the text. Can this be corrected so it remains at the end of the bottom pasted line?

I am also having a problem with one other modification. I want it to capitalize words following a hyphen and a space - "- " but not after hyphens that are not followed by space - "north-east". I tried this in line 97 of the attached macro but it isn't working. Is it possible to do what I want?

edit: also, it doesn't capitalize correctly after a numeral not followed by a period. So it does turn "5. test" into "5. Test", but it doesn't turn "5 test" into "5 Test". Can this be corrected?

I'm sorry if I'm asking for too much support on this macro--let me know. It has been very helpful for me!
• Attachment [protected]: frank99macro.macro [6,539 bytes]
7 days ago (modified 4 days ago)  • #20
Was this helpful?  Login to Vote  Login to Vote
<< DiscussionsReply