Visual studio 2008 在VisualStudio中对代码进行整体格式化
我继承了一个项目,其中所有私有变量(有数千个)都用一个空行分隔。比如说,Visual studio 2008 在VisualStudio中对代码进行整体格式化,visual-studio-2008,code-formatting,Visual Studio 2008,Code Formatting,我继承了一个项目,其中所有私有变量(有数千个)都用一个空行分隔。比如说, private pnlSecurityReport _pnlSecurityReport = null; private pnlCalendar _pnlCalendar = null; private CtlContacts _pnlContacts = null; private pnlEmails _pnlEmails = null; private CtlNotes
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?尝试将
\n\n
替换为\n
,选中使用正则表达式
。如果您有UltraEdit,可以替换<124;使用正则表达式:
查找:^p$替换:“(即无任何内容无引号,用于说明的引号)测试不彻底,但类似的操作可能会起作用:打开替换对话框,选中“正则表达式”,在“查找”文本框中输入
{^:b*:w+:b+:i:b+:i:b+=:b+*;$\n}\n
,在“替换为”文本框中输入\1
简言之;匹配与模式匹配的行单词标识符=值
后跟一个空行,标记所有匹配项(最后一个换行除外),然后用标记的表达式替换完整匹配项
这样做的好处是不会盲目地删除文件中的所有空行,而只会删除典型的字段或变量声明以及值赋值之后的空行
表达式细分:
{ - 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
在它上面运行StyleCop,它会让你在每个字段(//)上添加一条注释,这会让它看起来不那么烦人:P