我有一些如下所示的文本:
if ( != null)
command.Parameters.AddWithValue("@IsDeleted", acct.IsDeleted);
else
command.Parameters.AddWithValue("@IsDeleted", DBNull.Value);
if ( != null)
command.Parameters.AddWithValue("@MasterRecordId", acct.MasterRecordId);
else
command.Parameters.AddWithValue("@MasterRecordId", DBNull.Value);
if ( != null)
command.Parameters.AddWithValue("@Name", acct.Name);
我想让它看起来像:
if (acct.IsDeleted != null)
command.Parameters.AddWithValue("@IsDeleted", acct.IsDeleted);
else
command.Parameters.AddWithValue("@IsDeleted", DBNull.Value);
if (acct.MasterRecordId != null)
command.Parameters.AddWithValue("@MasterRecordId", acct.MasterRecordId);
else
command.Parameters.AddWithValue("@MasterRecordId", DBNull.Value);
if (acct.Name != null)
command.Parameters.AddWithValue("@Name", acct.Name);
因此基本上找到它( != null)
并用后续行中的值替换它acct.<field>
。
这可能吗?
答案1
- Ctrl+H
- 找什么:
(if \()( != null\)\R.+?)(\w+\.\w+)(?=\);$)
- 用。。。来代替:
$1$3$2$3
- 查看 环绕
- 查看 正则表达式
- Replace all
解释:
( # group 1
if \( # literally
) # end group
( # group 2
!= null\) # literally
\R # any kind of linebreak
.+? # 1 or more any character but newline
) # end group
( # group 3
\w+ # 1 or more word character
\. # a dot
\w+ # 1 or more word character
) # end group
(?=\);$) # positive lookahead make sure we have ");" at the end of line
截图(之后):