recase(string, [mode], flags)

Features wanted...
Post Reply
armsys
Posts: 557
Joined: 10 Mar 2012 12:40
Location: Hong Kong

recase(string, [mode], flags)

Post by armsys »

It would save tremendous coding effort by allowing an exclusion list.
recase(string, [mode], flags[, exclusion])
Currently, we apply casing to all words.
What if we wish to apply Title mode except some words such as SQL, ASP, PC, UK, and USA.
eg, recase($string, "title", 1, "SQL|ASP|PC|UK|USA")

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: recase(string, [mode], flags)

Post by highend »

I have nothing against that wish but I can't say that this is a "tremendous effort"...

Code: Select all

	 $string = "We need to get SQL as our primary Database";
    $string = replacelist(recase($string, "l"), "SQL|ASP|PC|UK|USA", "SQL|ASP|PC|UK|USA", "|", 0 , 1);
    text $string;
I'd wish we'd have a better inbuild regex engine... Then something like this would be possible (and a lot faster):

Code: Select all

	 $string = "We need to get SQL as our primary Database";
    $string = regexreplace(recase($string, "l"), "\b(SQL|ASP|PC|UK|USA)\b", "\U$1");
    text $string;
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: recase(string, [mode], flags)

Post by TheQwerty »

I recommend using scope=1 in that replacelist:

Code: Select all

$string = "Dear NATO, the USA needs to get SQL as our primary Database from the UK, ASAP! Good luck and raspberries.";
    $keepCaps = "NATO|ASAP|SQL|ASP|PC|UK|USA";

    $title = recase($string, 'title');
    $aString = replacelist($title, $keepCaps, $keepCaps, '|', 0, 0);
    $bString = replacelist($title, $keepCaps, $keepCaps, '|', 0, 1);

    text <<<>>>
Original:
$string
Title:
$title
Scope = 0:
$aString
Scope = 1:
$bString
>>>;
Results wrote:Original:
Dear NATO, the USA needs to get SQL as our primary Database from the UK, ASAP! Good luck and raspberries.
Title:
Dear Nato, The Usa Needs To Get Sql As Our Primary Database From The Uk, Asap! Good Luck And Raspberries.
Scope = 0:
Dear NATO, The USA Needs To Get SQL As Our Primary Database From The UK, ASAP! Good Luck And RASPberries.
Scope = 1:
Dear NATO, The USA Needs To Get SQL As Our Primary Database From The UK, ASAP! Good Luck And Raspberries.

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: recase(string, [mode], flags)

Post by PeterH »

Hm - if string contains 'All usable in USA'?

To me it seems a bit hard to optimize all this.
Win11 Pro 223H2 Gerrman

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: recase(string, [mode], flags)

Post by highend »

if string contains 'All usable in USA'?
the scope = 1 flag takes care of this
One of my scripts helped you out? Please donate via Paypal

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: recase(string, [mode], flags)

Post by TheQwerty »

But you're on your own when it comes to detecting the acronym/initialism that is also a real word: "Does that asp know ASP?"

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: recase(string, [mode], flags)

Post by PeterH »

highend wrote:
if string contains 'All usable in USA'?
the scope = 1 flag takes care of this
Oh - should have read documentation first!
I misinterpreted 1 as first (occurence). Didn't remember that "whole word" is possible. So correct: this is OK for a lot of situations. (For the rest: see reply of TheQwerty.) But much better than I thought...
Win11 Pro 223H2 Gerrman

armsys
Posts: 557
Joined: 10 Mar 2012 12:40
Location: Hong Kong

Re: recase(string, [mode], flags)

Post by armsys »

Thank all XYS gurus here for your merry and exciting exchange. :appl:
I didn't know the existence of the überfunction replacelist(). :oops:
I'm fond of TheQwerty's diplomat cable-like example, "Dear NATO, the USA needs to get SQL as our primary Database from the UK...".
The replacelist() should meet 99.99% acronym needs. :D
As result, I have no more burning desire for an enhanced recase(). :cup:
It would be nice if Don's regex engine supports the case conversion for backreferenced/captured group.
Thank you for your rapid help.

Post Reply