开发者

Formatting the code en-masse in Visual Studio

I've inherited a project where all the private variables, and there are thousands, are separated by a blank line. For instance,

    private pnlSecurityReport _pnlSecurityReport = null;

    private pnlCalendar _pnlCalendar = null;

    private CtlContacts _pnlContacts = null;

    priva开发者_运维问答te pnlEmails _pnlEmails = null;

    private CtlNotes _pnlNotes = null;

    private pnlRoles _pnlRoles = null;

    private pnlSecurity _pnlSecurity = null;

    private pnlSignatures _pnlSignatures = null;

This is really annoying. I'd like to remove the blank lines. Beyond writing my own tool to seek out and remove the extra line, is there a way to do this, perhaps, using RegEx-Fu in the Search and Replace dialog?


Try replacing \n\n with \n, with Use Regular Expressions checked.


Not very thoroughly tested, but something like this could work: open the Replace dialog, check "Regular Expressions", enter {^:b*:w+:b+:i:b+:i:b+=:b+.*;$\n}\n into the "Find" text box, and \1 in the "Replace with" text box.

In short; match lines that matches the pattern word identifier identifier = value; followed by a blank line, tag all of the match except the last newline and then replace the full match with the tagged expression.

This will have the upside of not blindly removing all blank lines from the file, but only those that follow after typical field- or variable declarations combined with value assignments.

Expression breakdown:

{    - Start of tagged expression
^    - Match beginning of line
:b*  - Zero or more whitespace characters (such as space or tab)
:w+  - One or more alphabetic characters
:b+  - One or more whitespace characters
:i   - An identifier string
:b+  - One or more whitespace characters
:i   - An identifier string
:b+  - One or more whitespace characters
=    - an equal sign
:b+  - One or more whitespace characters
.+   - One or more characters of any kind
;    - a semicolon
$    - end of the line
\n   - a newline
}    - end of tagged expression
\n   - a newline


If you have UltraEdit you can to Replace | Use Regular Expressions :

Find: ^p$
Replace:"" (i.e. nothing no quotes, quotes used for illustration)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜