Change case of letter after a semicolon

I have these strings on my clipboard:

one;two;three;four
One;Two;Three;Four

is there an easy way to change the case of the first letters after the semicolons?

On a side note: I guess that this would be a nice job to tackle with OSAX. However, this has been deprecated for macOS Mojave.

Hey Hans,

Easily done with a little bit of Perl.

-Chris


Capitalize Words Using a Perl Regular Expression v1.00.kmmacros (5.6 KB)

1 Like

KM is a great tool for those that are not skilled in the more complex scripting languages (of course, it is also a great tool to use with them). So, for those that might want a non-scripting KM solution, here's a (not so) simple macro.

In this case, because KM does NOT offer either of these:

  1. RegEx Replacement using the somewhat standard metacharacters for changing case (\L \U \l \u)
    (for more info see: Changing case with regular expressions )

  2. A function that will change case (there is a Filter action that changes case)

I have to recommend a scripting solution like that of Chris @ccstone, as it will be much faster for large strings than the workaround KM Macro below.

So, given

and assuming that you want to change ONLY the lower case to upper case after a semicolon, this example macro will do the job:

Example Results

image


MACRO:   Make Character after Delimiter Lower Case [Example]

~~~ VER: 1.0    2019-01-01 ~~~

DOWNLOAD:

Make Character after Delimiter Lower Case [Example].kmmacros (4.2 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


image


I have to admit that at first this somewhat stumpted me, but then I realized that a brute-force approach of redundant replacements would work. That is why it is slower. Having said that, for small strings (< 1000 characters) the difference in speed will not be noticable by most using a modern Mac.


Questions?

1 Like

Not in the current shipping version anyway…

2 Likes

I was playing around with the Objective-C regular expression functions for a bit and they don't seem to recognise these metacharacters either. I may go back for another play in case I did something wrong, but I was quite surprised by this.

NSString and NSRegularExpression (which I assume KM is using behind the scenes) use ICU Regular Expressions, which AFAIK don't support the case-changing flags.

1 Like