在 Visual Studio 中格式化代码
我继承了一个项目,其中所有私有变量(有数千个)都由空行分隔。例如,
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试将
\n\n
替换为\n
,并选中使用正则表达式
。Try replacing
\n\n
with\n
, withUse Regular Expressions
checked.没有经过非常彻底的测试,但类似这样的方法可以工作:打开“替换”对话框,选中“正则表达式”,输入
{^:b*:w+:b+:i:b+:i:b+=:b+.*; $\n}\n
放入“查找”文本框中,\1
放入“替换为”文本框中。简而言之;匹配与模式
wordidentifieridentifier=value;
匹配的行,后跟一个空行,标记除最后一个换行符之外的所有匹配项,然后用标记的表达式替换完整匹配项。这样做的好处是不会盲目地从文件中删除所有空行,而只会删除典型字段或变量声明与值分配之后的空行。
表达细目:
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:
如果您有 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)