Initially we planned to have old convention of having m_ prefix for class variables. But now requirement has come to replace all the m_VaribaleName to this.variableName, i.e. remove the m_ and make the first character after m_ lowercase开发者_Python百科.
I can search and replace m_ with this. but this doesn't rename the variable's first character to lowercase. After search and replace if I use re-factoring tool to rename VariableName to variableName this also renames the property already exists with VariableName.
I am wondering is there any regex, tool, macro to make this task automated.
Resharper will highlight all such errors in a solution, and fix them individually, but I don't think it can fix all of them with a single command. Still, it's easy enough to navigate between errors that it finds.
You can do this in emacs.
Open your file (C-x C-f
) and do M-x replace-regexp
.
Let's say the name of the variable is Variable
.
Your regexp query would replace \(V\)ariable
for \,(downcase \1)ariable
.
The \,
tells emacs the following statement is a lisp expression.
Additionally, if you wanted to replace the m_ at the same time you could do replace m_\(V\)ariable
for \,(downcase \1)ariable
.
This will take care of all instances in a file at the same time and emacs does remember your last replace-regexp query so you do not have to retype it for multiple files. Furthermore, there is a way using DIRED mode to do the replace-regexp on multiple files at the same time.
Open up a directory on DIRED mode (C-x C-f DIR_NAME
), mark the files you want by going over them (you can navigate using n
and p
) by pressing m
. Once the files you want to process are marked press Q
(capital-case). You will get the same regexp prompt as if you did a single file, enter the regexp, RET
, the replacement, and RET
. It will open up each file at a time, press !
for every file to replace all reg-exps in that file.
After that, you still have to save the files. Which you can do with C-s
and then !
.
精彩评论