Capitalize all 2 Letter Words

Advanced Renamer forum
#1 : 17/03-19 04:06
Jesson
Jesson
Posts: 6
I'm trying to think of a pattern to capitalize all 2 letter words but fails to do so. Could anyone help? Thanks in advance.


17/03-19 04:06
#2 : 17/03-19 09:17
Stefan
Stefan
Posts: 274
Reply to #1:
You can try List replace method
https://www.advancedrenamer.com/user_guide/metho d_listreplace

on > ON
is > IS
to > TO


but best with "[x]Use regular expressions"

\bon\b > ON
\bis\b > IS
\bto\b > TO



 


17/03-19 09:17
#3 : 17/03-19 10:54
David Lee
David Lee
Posts: 1125
Reply to #1:

To capitalize ALL two letter words you will need to use a Regular Expression in a script.

Enter the following function as the pre-batch script:

function changeCase(str) {
return str.replace(/\b\w*/g, function(txt){
if (txt.length == 2) {
txt = txt.toUpperCase();
}
return txt;
});
}

Then in the main script window:

return changeCase(item.name);



17/03-19 10:54 - edited 17/03-19 11:31
#4 : 17/03-19 11:17
David Lee
David Lee
Posts: 1125
Reply to #3:
My previous script will leave existing capitalization of non-two-letter words unchanged.

If you want ONLY two letter words capitalized then convert the filenames to lowercase before calling the function in the pre-batch script.

ie - in the main script window:

return changeCase(item.name.toLowerCase());


17/03-19 11:17 - edited 17/03-19 11:29
#5 : 17/03-19 11:50
Jesson
Jesson
Posts: 6
Reply to #2:
Thank you for your effort but that is not what I'm looking for as it is very inefficient if I were to capitalized all 2 letter words


17/03-19 11:50 - edited 17/03-19 12:01
#6 : 17/03-19 11:59
Jesson
Jesson
Posts: 6
Reply to #3:
It works. I knew scripting method was unavoidable. I don't know anything about how scripting work or how to make one so I avoid it. I thought it could be achieved efficiently without scripting method so I tried asking in the forum. Maybe Kim should add a this feature?

Anyway problem solved and thanks to all


17/03-19 11:59 - edited 17/03-19 12:00