How to capitalize each letter coming after a particular string

Daniele Brunengo
Daniele Brunengo used Ask the Experts™
Hello, I'm editing a PO translation file for a Wordpress website.
The former translator forgot to capitalize most first letters in sentences.

POedit doesn't allow me to capitalize each first letter, so I thought I'd use Notepad++ (but feel free to suggest something else).

I need to select each letter coming after this particular string: msgstr "
and capitalize it.

Maybe with Regex, not an expert though. Can somebody lend a hand? Thanks.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Are you OK with Microsoft Word?
If yes, could you paster here a reference text just as example?
Daniele BrunengoIT Consultant, Web Designer


Here's an extract. All words after 'msgstr "' need to begin with a capital letter.

#: E:\!our theme
#: wordpress\residence\!versions\1.09\wpresidence/libs/property.php:458
msgid "Bedrooms: "
msgstr "camere da letto:"

#: E:\!our theme
#: wordpress\residence\!versions\1.09\wpresidence/libs/property.php:467
msgid "Bathrooms: "
msgstr "bagni:"

#: E:\!our theme
#: wordpress\residence\!versions\1.09\wpresidence/libs/property.php:550
#: wordpress\residence\!versions\1.09\wpresidence/templates/submit_templates/property_location.php:173
msgid "Place Pin with Property Address"
msgstr "posizionare Pin con indirizzo dell'immobile"

Open in new window

Could you confirm if after msgstr string is always space+quotation mark before the word that you want to capitalize starts?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Daniele BrunengoIT Consultant, Web Designer


Yes it is.
Then I guess one solution would be to import it in Microsoft Word and use some VBA code.
Search for the string <msgstr "> and then find the letter/character following that string. Then capitalize it.
I do not know all the steps now, but this is how I would do it.
The difficulty that I have now is to find the character after that string. The string itself is easy to find, but to specify the following letter I have no idea for the moment. The rest should not be so complicated.
Let's see what other people suggest. If in mean time I have a solution I will let you know.
Daniele BrunengoIT Consultant, Web Designer


Thanks. I think Regex should allow to select the following character, but I'm not sure.
Top Expert 2014

The regex find pattern should be simple enough.
\. +[a-z]

The replacement will depend on the tool you are using.
Top Expert 2014

This pattern is a bit more inclusive:
(?:^|\. +)([a-z])
Top Expert 2016

you could use the macro Recorder in visual Studio (download vs express or vs community for free if not available).

open the text file in the vs text editor.

CTRL+SHIFT+R   starts the macro Recorder
CTRL+F         opens search window
msgstr "       enter this at Find What
               check find options 'Match case' and 'Match whole word'
F3             leaves find window and selects search string
<--            cancels selection 
CTRL+-->       moves text cursor to " without selection
-->            moves to first character after "
CTRL+SHIFT+U   capatalizes first character after "
CTRL+SHIFT+R   ends macro recording

Open in new window

now you could use the macro by CTRL+SHIFT+P until all occurrences were changed.

note, of course you could use any macro recorder for this task. some control sequences may differ, though.

William NettmannPHP Web Developer

Simplest solution:
$text = "Your file's contents";
$Text = str_replace('['msgstr "a','msgstr "b','etc',],['msgstr "A','msgstr "B','Etc',],$text);

Open in new window

str_replace() will replace each occurrence of a string in the first array with the equivalent string in the second array by position.

You could use a loop to create the arrays first to cut down on typing.
Top Expert 2014

If you have Notepad++ with the TextFX plug-in installed, you can select all the text and do the following on the menu bar:
TextFX | TextFX Characters | Sentence Case

Note: The "|" represents the appearance of a sub menu
PHP Web Developer
The whole thing:
for ($c = 97; $c <= 122; $c++) {
  $lowercase[] = 'msgstr "' . chr($c);
  $uppercase[] = 'msgstr "' . chr($c - 32);
$text = "Your Text";
$Text = str_replace($lowercase, $uppercase, $text);

Open in new window

Daniele BrunengoIT Consultant, Web Designer


That worked great. It was the only solution to actually solve the problem in one step. I thank you all for your input.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial