Jump to content
Macro Express Forums

Capitalizing The First Letter


Recommended Posts

Hi Ashley,


attached is a playable macro which will do what you want


Set String T1 = Peter

Modify String Copy Char 1 of T1 to T2

Modify String Copy T2 to T3

Modify String Uppercase T3

Modify String Rplace T2 with T3 in T1 (NOT all instances)


There are probably several other ways to do it too.




Link to comment
Share on other sites

I had a similar situation a few weeks ago. One of my customers had downloaded a mailing list (all in uppercase characters) and wanted to quickly convert the names and addresses to capitalized words. I found a command in the "PGM Functions Library" named "{ String - Proper }" that did the job. The library is sold by the same people that sponsor this forum. I think the whole library was $29.95. And I did notice that they are having a 30% off sale this weekend <_< but, like I said, I got mine a few weeks ago. Anyway, here is a link to more information about the library and here is a link to the free manual.


Good Luck!

Link to comment
Share on other sites

  • 2 weeks later...

Hi Ashley,


I wrote a macro a couple of weeks ago that capitalizes the first letter in EVERY word in a text string. It is not what one would call "title case" with some words such as "the" in lower case.


The macro starts off basically as Pete showed. It then works through the string looking for spaces and sets a flag if one found. The next non-space character is capitalized and the flag reset. It is designed to change the first letter after a space or "-". Other exceptions are easy to add - see listing in Scripting Editor


It will not presently handle a cr/lf so the first words in multiline selections are not changed. It is designed to be run after text in some document has been selected (highlighted). The hotkey is pressed, text is copied, processed and then pasted back. If the text is input via another method the macro needs to be modified.


Macro worked for my purposes but not extensively tested.


Link to comment
Share on other sites

Thanks to Nicolas' help with Ascii codes, I have upated my macro to work with all the common text delimiters, space, comma, semi-colon, colon, hyphen, underscore, tab, line feed. It is fairly clear in the macro how to add (or remove) delimiters in plain text or ascii character code.


The first character in a text string, and any character after a delimiter, will be capitalized. Example (all lines of text selected):


abc -def ghi- jkl ;mno



Abc -Def Ghi- Jkl ;Mno



Link to comment
Share on other sites

smsc228.gif you could enhance your macro to insert missing spaces / remove extra ones ... for instance :


- if you have two spaces, it should remove the second one

- there should be a space after and no space before "single" symbols such as commas and dots

- there should be a space after and another one before "double" symbols such as colons, semi-colons


(at least in France, because I know it depends on the country)

Link to comment
Share on other sites

I'm sure there are lots of variations you could make but you are then getting into application-specific. What suits one person does not suit another.


For very specific uses, a custom macro can be written. For general use it is better to have a suite of simple macros that can be put together in different combinations to produce the required results.


Regarding spaces, I have another macro that goes though a block of text reducing all the gaps between words to one space (though I will have to modify to cope with tabs, ascii 9!)

Link to comment
Share on other sites

1. Invert

If accidently I hit the key Capslock it would be very helpful if the text written false could be automatically corrected instead of typing again from scratch. The best solution would be if each character would be inverted, so that a capital letter would become small and a small letter capitalized.


2. Capital letters

If all letters are capitalized your macro doesn't work (yet) :-)

But if I add <TMVAR2:13:01:00:000:000:><REM2:Change all letters to lowercase>.....

Link to comment
Share on other sites

Funny that you should mention that Bernd. I started using the Proper function from the pgm suite and it does lower-case everything first before upper-casing the first letter. It even capitalizes the first character in a word if the character before it is a punctuation mark, and not just whitespace.


I do want to thank everyone for their answers.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...