Use Notepad++ to change under_score_case to CamelCase?
I have a solution that's long and convoluted, but will work in Notepad++. It requires the use of regex, optionally normal search and replace, as well as TextFX.
- Add a placeholder character to the front of each word, I chose
Z
. It probably doesn't have to be alphabetic, but it's easier for the last step. Using regex, search for\<([^ ]*)\>
and replace withZ\1
. - Replace existing spaces with a unique placeholder sequence. I chose #space#. This can be done with regex, but I prefer using normal or expanded.
- Replace underscores with spaces. If there are any underscores that shouldn't be replaced, then a custom regex is probably required. I just did a straight search and replace.
- Select all text, and from the TextFX menu, select
TextFX Characters -> Proper Case
. - Now we need to reverse the first 3 steps. Search for spaces, and replace them with nothing. Then search for your space placeholder sequence, and replace with a space. Finally, using regex, search for
\<Z([^ ]*)\>
and replace with\1
.
A simple find/replace will do this in NP++:
Find: [_]{1,1}([a-z])
Replace: \U$1
You need to select the 'Regular expression' radio button in the Replace panel for this to work.
I typically use vim myself as an editor. The following regular expression accomplishes what you're trying to do in vim:
%s/_\([a-zA-Z]\)/\u\1/g
From what I can tell (I fooled around with NP++ for a bit), Notepad++ does not understand the uppercase macro \u
in Perl Regexp. You may not be able to do this entirely with Notepad++. Hopefully, someone will prove me wrong and make your day.
You can do this with one step in notepad++, which is probably more useful:
Find: ([a-z]+)[_]?([a-z]?)([a-z]+)[_]?([a-z]?)([a-z]+)[_]?([a-z]?)([a-z]+)\.php
Replace: $1\U$2\L$3\U$4\L$5\U$6\L$7
The only issue with this, is that you need to know the max time the under score can be present and how the string ends. In the above example, i'm replacing php file names to camelCase, knowing that the under score cannot be present more than 3 times, less is no problem.
My personal favourite is sed. It is lightning fast:
> echo make_me_camel_case_please | sed -e 's/(_[a-z])/\U\1/g' -e 's/_//g'
makeMeCamelCasePlease
You can use the -i option to perform the replace on a file you are editing and N++ should pick up the change.
This will also delete all underscores, as with some above solutions. That can be fixed if this is an issue.