在 Visual Studio 中格式化代码

发布于 2024-08-25 12:40:45 字数 520 浏览 6 评论 0原文

我继承了一个项目,其中所有私有变量(有数千个)都由空行分隔。例如,

    private pnlSecurityReport _pnlSecurityReport = null;

    private pnlCalendar _pnlCalendar = null;

    private CtlContacts _pnlContacts = null;

    private pnlEmails _pnlEmails = null;

    private CtlNotes _pnlNotes = null;

    private pnlRoles _pnlRoles = null;

    private pnlSecurity _pnlSecurity = null;

    private pnlSignatures _pnlSignatures = null;

这真的很烦人。我想删除空白行。除了编写我自己的工具来查找并删除多余的行之外,还有没有办法做到这一点,也许可以在“搜索和替换”对话框中使用 RegEx-Fu?

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;

    private 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

或十年 2024-09-01 12:40:45

尝试将 \n\n 替换为 \n,并选中使用正则表达式

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

撩心不撩汉 2024-09-01 12:40:45

没有经过非常彻底的测试,但类似这样的方法可以工作:打开“替换”对话框,选中“正则表达式”,输入 {^:b*:w+:b+:i:b+:i:b+=:b+.*; $\n}\n 放入“查找”文本框中,\1 放入“替换为”文本框中。

简而言之;匹配与模式 wordidentifieridentifier=value; 匹配的行,后跟一个空行,标记除最后一个换行符之外的所有匹配项,然后用标记的表达式替换完整匹配项。

这样做的好处是不会盲目地从文件中删除所有空行,而只会删除典型字段或变量声明与值分配之后的空行。

表达细目:

{    - 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

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
酷炫老祖宗 2024-09-01 12:40:45

如果您有 UltraEdit,您可以替换 |使用正则表达式:

查找:^p$
替换:“”(即没有任何引号,引号用于说明)

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文