Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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
Frank99's profile on WallpaperFusion.com
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!
Mar 2, 2019  • #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.
Mar 5, 2019  • #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 :)
Mar 12, 2019  • #19
Frank99's profile on WallpaperFusion.com
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]
Mar 15, 2019 (modified Mar 18, 2019)  • #20
Frank99's profile on WallpaperFusion.com
Hi, it's been a month, so just wanted to bump this thread in case it was forgotten.

Also, one other question. In the list of words to capitalize, I'm finding that two-word phrases like "Hong Kong" are not being capitalized. Is it because they are two words, or is there some other explanation? Is there any way to capitalize two-word phrases?
Apr 18, 2019  • #21
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Sorry for the delay, some how this dropped off my list of open requests!

To be totally honest, it is starting to get a bit complicated to handle all of the different usage cases for this Macro, but I'll see what I can do. I'll have another look at it later next week hopefully :)
Apr 19, 2019  • #22
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, I've completely re-written this macro, hopefully it's what you're looking for. If not, please let me know. Small tweaks should be much easier now.

Thanks!
• Attachment: Uppercase for Citations.cfmacro [22,952 bytes]
Jul 3, 2019  • #23
Frank99's profile on WallpaperFusion.com
Great work! Just one question about modifying it. It currently reads:
// Capitalize words after colons or hyphens
if (words[i - 1].EndsWith(":", StringComparison.OrdinalIgnoreCase) ||
words[i - 1].EndsWith("-", StringComparison.OrdinalIgnoreCase)

What do I add if I want to also capitalize words after questions marks or other punctuation? I tried to fix it myself but it didn't work.
Jul 8, 2019  • #24
Keith Lammers (BFS)'s profile on WallpaperFusion.com
You'll need to add the || (which means "or") to the end of the existing line, then add your next condition, like this:

Code

if (words[i - 1].EndsWith(":", StringComparison.OrdinalIgnoreCase) ||
words[i - 1].EndsWith("-", StringComparison.OrdinalIgnoreCase) ||
words[i - 1].EndsWith("?", StringComparison.OrdinalIgnoreCase)
Jul 8, 2019 (modified Jul 8, 2019)  • #25
Frank99's profile on WallpaperFusion.com
The macro is generally working but is producing a mistake I can't explain. For the text string, "The Psychological Functions of Justice in Mass Media", when I run the macro, I get "The psychological functions of Justice in mass media" with the word "Justice" capitalized. It should not be capitalized. I that word is not in the list of exceptions. Can you explain? I've attached my version with a longer list of exceptions than the one you sent me. Thanks!

Edit: another example: "Universal Morality, Mediated Narratives, and Neural Synchrony" becomes "Universal morality, mediated narratives, and Neural synchrony" - "Neural" is mistakenly capitalized. But "A Model of Intuitive Morality and Exemplars" correctly becomes "A model of intuitive morality and exemplars". So weird.
• Attachment [protected]: Uppercase for Citations (user modify).cfmacro [41,600 bytes]
Jul 26, 2019 (modified Jul 26, 2019)  • #26
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Weird! When I run my original version, "justice" doesn't get capitalized, but when I run yours, it does. I'll have a look at this and see what I can find out.
Jul 26, 2019  • #27
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, could you try this one out and let me know how it goes? I also fixed a bug where it wouldn't capitalize exception words if they had a space in them.
Jul 26, 2019  • #28
Frank99's profile on WallpaperFusion.com
Thanks for the macro. When I run the macro on "The Psychological Functions of Justice in Mass Media" I get "The psychological functions of jUStice in mass media", presumably because "US" is in the exceptions list. I suppose if you are going to re-capitalize the exceptions items, you will need to check that they are stand-alone words.

BTW, would you mind removing my personal name from the macro name you attached? I tried to change it in the one I attached but I guess it was in the code somehow. Thanks!
Jul 27, 2019 (modified Jul 27, 2019)  • #29
Keith Lammers (BFS)'s profile on WallpaperFusion.com
That's strange, because I made it check for a space before and after the exception word. Does line 114 look like this?

Code

finalOutput = finalOutput.Replace(" " + exceptionWord.ToLower() + " ", " " + exceptionWord + " ");
Jul 29, 2019  • #30
Frank99's profile on WallpaperFusion.com
Hi, 117 doesn't look like that. I've attached my version. But now it changes "The Psychological Functions of Justice in Mass Media" into "The psychological functions of Justice in mass media", which is better but still not what I'm trying to get. Your help is very appreciated!
• Attachment [protected]: Uppercase for Citations (user modify).cfmacro [41,592 bytes]
Aug 26, 2019  • #31
Frank99's profile on WallpaperFusion.com
Just following up on the last message. I just got another example: it changes "Seeing Ourselves Through Technology: How We Use Selfies, Blogs and Wearable Devices to See and Shape Ourselves" into "Seeing ourselves through technology: How we Use selfies, blogs and wearable devices to see and shape ourselves"

No idea why the "Use" is capitalized in the 2nd case.

I have again attached my script. Thanks.
• Attachment [protected]: Uppercase for Citations (user modify).cfmacro [42,200 bytes]
Sep 14, 2019  • #32
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Sorry for the delay on this. Could you try this updated version?
Sep 16, 2019  • #33
Frank99's profile on WallpaperFusion.com
It works! If it's easy to explain, I'd love to know what you did that fixed it.
Sep 17, 2019  • #34
Keith Lammers (BFS)'s profile on WallpaperFusion.com
I forgot to add the word boundary check in when I re-did the script, so it was matching on the "US" exception word again.

I introduced another bug when I did that yesterday, but I've fixed that up now too. Please try this one out :)
Sep 17, 2019  • #35
Frank99's profile on WallpaperFusion.com
OK, in an attempt to make this the longest thread on the forum, I have another question. I had a title that wouldn't capitalize properly because it used a "smart" apostrophe rather than a normal one. So "Where’s the X?" came out as "Where’S the x?". I tried changing the macro to replace smart apostrophes with this:

Code

// Fix smart apostrophes
text = text.Replace("’", "'");


That worked, but I also want to fix smart quotes, and the following code fails to compile:

Code

text = text.Replace("“", """);
text = text.Replace("”", """);


How can I fix that? Thanks.
Oct 24, 2019  • #36
Keith Lammers (BFS)'s profile on WallpaperFusion.com
The middle quote mark in the replace text needs to be escaped with a backslash, like this:

Code

text = text.Replace("“", "\"");
text = text.Replace("”", "\"");
Oct 24, 2019  • #37
Frank99's profile on WallpaperFusion.com
That worked! I've now realized that the change to Title Case macro you made for me has two problems. First, it incorrectly capitalizes the final "s" in titles with possessives, so "the critic´s share" becomes "The Critic´S Share". Also, I tried to modify it to change smart apostrophes to dumb ones, but it's not working. I've attached the macro. Can you suggest a fix?
• Attachment [protected]: Convert Text to Title Case (user modify) 2019-11-05.cfmacro [1,336 bytes]
Nov 5, 2019  • #38
Keith Lammers (BFS)'s profile on WallpaperFusion.com
I don't think the export worked. I tried importing it but it's just a blank Macro. Could you try again?
Nov 5, 2019  • #39
Frank99's profile on WallpaperFusion.com
OK!
• Attachment [protected]: Convert Text to Title Case (user modify) 2019-11-07.cfmacro [15,984 bytes]
Nov 7, 2019  • #40
Keith Lammers (BFS)'s profile on WallpaperFusion.com
Ok, try this one :)
Nov 7, 2019  • #41
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)