Converting capital letters to small letters

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

zabros2020
Pro Scripter
Posts: 70
Joined: Sun May 03, 2009 11:49 pm
Location: AU

Converting capital letters to small letters

Post by zabros2020 » Fri Jul 03, 2009 1:53 am

hey guys.

I currently have a script that locates a client's name for example JOHN SMITH, and later uses it to send an e-mail to that customer. I was wondering how one would go about writting a script to change the case of the letters so that the name is John Smith.

The only way i can think of is having two lists with all the capital letters and all the small letters and having an iterative process which would change them, given that the character is not a space or the letter after a sapce.

is there a better way?

Thanks for your help

p.s. i looked everywhere on the forum, i couldn't find such a thing

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Jul 03, 2009 2:24 am

I don;t recall the exact syntax right now, but that is something you could do with RegEx strings.

Macro Scheduler versions starting with 11.1.05 Mar 02 2009, has its own RegEx command, or you can use the VBS RegEx command with earlier versions.

Need to research RegEx usage of [:upper:], [:lower:], \l,\L, \u, \U.

Cannot test now, but here are some thoughts:

Search for this needle:
([[:upper:]]{1})([[:upper:]]+) should find all strings that are all UPPERCASE and group the first letter separate from the second group of remaining letters
Examples: String of "FRANK and BILL and Sam" would result in FRANK and BILL as being found.
String of "MARY SMITH and Sally Jones and TOM SWIFT" would result in MARY SMITH and TOM SWIFT being found.

(NOTE: Searching for \w[[:upper:]] will also find the same words, but does not isolate the groups of characters. But could be used with a replacement string to Initialize if you can find that. Different versions of RegEx have that tool, I am not sure about Macro Scheduler or VBS right now).

The replacement string for the needle still needs to be figured out.
For my initial Search string the replacement should probably be something like this:
$1\l$2
or
$1\L$2\E

Hope I can return soon....
Last edited by Bob Hansen on Sat Jul 04, 2009 1:19 am, edited 1 time in total.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jul 03, 2009 2:52 pm

Whichever method you use remember that it's not as simple as capitalizing after a space, you also have to consider hyphenated names, and then there are the ones that have embedded caps like "McKnight", and the ones where the character after the space isn't capitalized like "Nouri al-Maliki" , and, and :wink:

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jul 04, 2009 2:02 am

I just got a chance to check out my RegEx, and it does not work!

I need to get that figured out before I continue with the replacement string.

This expression ([[:upper:]]{1})([[:upper:]]+) works good for me on the online utility at http://www.gskinner.com/RegExr/
But when I try it in Macro Scheduler instead of a count of 4, and the four matching strings, I get a count of 8 and every word comes up as a match.

Will be back later with an answer..........

And Me_Again is certainly correct about having to watch/plan for those special exceptions. But I suspect it will just take a few more RegEx strings to handle most of them.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jul 04, 2009 2:11 pm

It appears that the RegEx expression is ignoring CASE.

I am an old school RegEx user, not familiar with EasyPatterns, but I tried that also with no success. I used [twoOrMore upper] but there was no clear example in the EasyPatterns Reference link, and I am not sure of the syntax. But I got the same result as normal RegEx.

So, I need to find out how to turn off IgnoreCase in Macro Scheduler and EasyPatterns syntax expressions. VBS and TextPipe both have a parameter to do that, perhaps Macro Scheduler also needs a similar switch? One could perhaps be added to the end of the existing function to help backwards compatibility?

===============
The \l and the \L...\E are not working, even on the wrong selections that are made. This makes me more certain that something is missing re CASE support with the RegEx function. The perl modifier "i" probably has some role along with perllocale? I am not a perl expert, so I am just digging in to find a cause/solution.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Jul 04, 2009 8:48 pm

How about:

Code: Select all

Let>name=JOHN SMITH
RegEx>(?<=\w)(.){1},{Upper(%name%)},0,matches,num,1,x,temp_name

Let>new_name=
Let>pos=0
Repeat>pos
  Let>pos=pos+1
  Let>ch={Copy(%temp_name%,%pos%,1)}
  If>ch=x
    Let>ch={Copy(Lower(%name%),%pos%,1)}
  Endif
  Let>new_name=%new_name%%ch%
Until>pos={Length(%temp_name%)}

MessageModal>new_name
It would be really nice if we could just specify Lower($1) as the replacement value and therefore do it all in one line. But that isn't supported .... yet ....
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sat Jul 04, 2009 11:11 pm

If the string is being scanned character by character anyway, then old technology will work too for those of use without the new regex toy to play with:

Code: Select all

VBSTART
VBEND
Let>name=JOHN david Q. SMITH
Let>new_name=
Let>pos=0
Repeat>pos
Let>prepos=pos
Let>pos=pos+1
Mid>name,pos,1,ch
Mid>name,prepos,1,ch0
IF>{(%pos%=1) OR (%ch0%=" ")}
VBEVAL>UCase("%ch%"),ch
ELSE
VBEVAL>LCase("%ch%"),ch
ENDIF
Let>new_name=%new_name%%ch%
Until>pos={Length(%name%)}
MDL>new_name


User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Jul 05, 2009 9:17 pm

In another post Marcus explained that you can turn on Case Sensitivity for RegEx by putting (?-i) in front ot the needle pattern. So, when I used that I ended up with just the four UPPERCASE names as expected vs. all of the words.

But the replacement string is still not working.

Code: Select all

Let>vHaystack=MARY SMITH and Sally Jones and TOM SWIFT
Let>vNeedle=(?-i)([[:upper:]]{1})([[:upper:]]+)
Regex(%vNeedle%,%vHaystack%,0,vNames,vCount,1,$1\l$2,vInitials
MessageModal>The modifed names are %vInitials%
For the replacement string I have tried $1\l$2, $1\L$2\E, (?-i)$1\l$2, and (?-i)$1\L$2\E, but none of them work. What is the correct syntax to replace group 2 with lower case characters?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Jul 05, 2009 9:26 pm

You can't. RegEx finds a match but doesn't modify and you're asking it to *find* upper or lower case match. Using the case modifier tells it what to match not how to replace.

Ideally it would be nice to specify something like {Upper($1)} as the replace string - I.e be able to use the complex expression function Upper with the $1 match var as the parm. But that is something for the future.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Mon Jul 06, 2009 2:05 am

Aah!, Not the answer that I wanted. I have used another program with RegEx that has that capability. I thought that the same feature would be present in this version of RegEx.

Funduc uses %1 for UPPERCASE
TextPad uses \L\1\E for lowercase and \U\1\E for UPPERCASE
Perl uses \L$1\E for lowercase and \U$1\E for UPPERCASE, and I thought that RegEx was perl compatible?

Re, for the future, should I place a request in the Enhancements forum, or can you pick that up from here. Would really like to be able to use that.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jul 06, 2009 5:08 am

This is not a feature of RegEx - RegEx is for *finding* matches - but a feature of the apps you refer to.

I agree (and have already said) it would be nice to do same in Macro Scheduler. So no need to post anything anywhere. It's already on the wish list.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Mon Jul 06, 2009 7:38 pm

mtettmar wrote:It's already on the wish list.
:D

Thanks Marcus... and congratulations - all the best for the future.
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Jul 07, 2009 1:37 am

Thanks Marcus. You are always there making us happy!
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jul 10, 2009 9:23 am

I've just realised something! All you need is:

Code: Select all

Let>name=JOHN SMITH
RegEx>(?<=\w)(.){1},{Upper(%name%)},0,matches,num,1," + Lower("$1") + ",temp_name
Let>name={%temp_name%}
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jul 11, 2009 12:40 am

Thanks Marcus, I will try to play with that over the weekend.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts