Script to Capitalize Words' First Letters

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Jack99
Posts: 14
Joined: 03 Jun 2020 06:10

Script to Capitalize Words' First Letters

Post by Jack99 »

Hi, I have just created a customized toolbar button, which executes the next renaming function:

rename s, " >."

I would like to extend its capabilities, starting by making it capitalizes words. But after reading the included help file,
I still didn't find the right way of doing that. It should perform the same renaming routine as when the predefined
"A* A*.aaa" function is invoked.

Thanks.

RalphM
Posts: 1932
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Script to Capitalize Words' First Letters

Post by RalphM »

Just use the command id for built in functions (#138 or #126, depending on which camel case you want).
Help/Show Command ID's in menu toggles the display of the id's.
Ralph :)
(OS: W11 22H2 Home x64 - XY: Current beta - Office 2019 32-bit - Display: 1920x1080 @ 125%)

Jack99
Posts: 14
Joined: 03 Jun 2020 06:10

Re: Script to Capitalize Words' First Letters

Post by Jack99 »

I'm being able to run one script at a time, but I can't make them run simultaneously. What I have tried:

rename s, " >."; ::#138;rename s, "A123/a123";


Expected result:

"The quick brown fox jumps over the lazy dog A123"

"The.Quick.Brown.Fox.Jumps.Over.The.Lazy.Dog.a123"

Similarly, when I try to combine commands into the "Rename Special > Search and Replace" function, they are executed
separately only (without quotes):

" >. "
"A123/a123 /c"

And the one that capitalizes first letters, which I don't know. :veryconfused:

highend
Posts: 13277
Joined: 06 Feb 2011 00:33

Re: Script to Capitalize Words' First Letters

Post by highend »

rename s, " >."; #138; rename s, "A123/a123";
Works here. But the third command isn't even necessary. #138 will already "decapitalize" the extension.
And the one that capitalizes first letters, which I don't know.
That function (apart from the id) doesn't do that. You would need to script that.
One of my scripts helped you out? Please donate via Paypal

Jack99
Posts: 14
Joined: 03 Jun 2020 06:10

Re: Script to Capitalize Words' First Letters

Post by Jack99 »

As you mentioned, after removing the "::", the command worked as expected. :) But I kept the last command as well, since
that "A123" from the example isn't an extension, but a starting letter from a single word that might be already capitalized and I
need it as lower case.

Could the commands be combined as well, when using the "Rename Special > Search and Replace" function? At least the allowed commands to use with it, without having to create a specific script.
Last edited by Jack99 on 03 Jun 2020 10:18, edited 1 time in total.

highend
Posts: 13277
Joined: 06 Feb 2011 00:33

Re: Script to Capitalize Words' First Letters

Post by highend »

No, you can't combine them via the context menu entry.
One of my scripts helped you out? Please donate via Paypal

highend
Posts: 13277
Joined: 06 Feb 2011 00:33

Re: Script to Capitalize Words' First Letters

Post by highend »

To show you a way how things can be scripted...

Code: Select all

    $from = " ";
    $to   = ".";
    $exclude = "A123";

    $sample = "The quick A123 brown fox jumps over the lazy dog";

    $new = CapitalizeWords($sample, $exclude);
    $new = replace($new, $from, $to);

    // Rename item via "renameitem"
    text $new;


// $exclusions must be separated by "|"
function CapitalizeWords($string, $exclusions) {
    $string = recase($string, "camel");

    foreach($item, $exclusions, "|", "e") {
        if (strpos($string, $item, 0, 1) != -1) { $string = replace($string, $item, recase($item, "l")); }
    }
    return $string;
}
One of my scripts helped you out? Please donate via Paypal

Jack99
Posts: 14
Joined: 03 Jun 2020 06:10

Re: Script to Capitalize Words' First Letters

Post by Jack99 »

OK, I will try that one later.

By the way, I just noticed that if the above script is put like this:

Code: Select all

rename s, " >."; rename s, "X264/x264"; #138;
The " rename s, X264/x264" part will have no effect at all. The only difference being the commands' order (#138 in the third place, instead the second one).

Thanks.

highend
Posts: 13277
Joined: 06 Feb 2011 00:33

Re: Script to Capitalize Words' First Letters

Post by highend »

The " rename s, X264/x264" part will have no effect at all.
Of course it has an effect, but the third command will negate it...
One of my scripts helped you out? Please donate via Paypal

Jack99
Posts: 14
Joined: 03 Jun 2020 06:10

Re: Script to Capitalize Words' First Letters

Post by Jack99 »

You are right, the "#138" command will capitalize it again. :)

Post Reply