日期:2014-05-20 浏览次数:20984 次
If str1 = "" AndAlso str2 = "" Then ... End If If str1 = "" OrElse str2 = "" Then ... End If
If str1.Length = 0 AndAlso str2.Length = 0 Then ... End If If str1.Length = 0 OrElse str2.Length = 0 Then ... End If
Dim rg8 As Regex = New Regex("^If\s(?<key>\w+)\s=\s""\sThen") Console.WriteLine(rg8.Replace("If str = "" Then", "If ${key}.Length = 0 Then")) 'Output:If str.Length = 0 Then
If str1 = "" AndAlso (str2 = "" OrElse str3 = "" ) OrElse str4 = "" Then ... End If
void Main() { string str=@"If str1 = """" AndAlso str2 = """" Then ... End If If str1 = """" OrElse str2 = """" Then ... End If If str1 = """" AndAlso (str2 = """" OrElse str3 = """" ) OrElse str4 = """" Then ... End If"; str=Regex.Replace(str,@"(If|AndAlso|OrElse)\s+((\S+)\s*=\s*"""")","$1 $3.Length = 0"); Console.WriteLine(str); /* If str1.Length = 0 AndAlso str2.Length = 0 Then ... End If If str1.Length = 0 OrElse str2.Length = 0 Then ... End If If str1.Length = 0 AndAlso (str2.Length = 0 OrElse str3.Length = 0 ) OrElse str4.Length = 0 Then ... End If */ }
------解决方案--------------------
不用什么都想着一步全天,直接用DW批量分别替换,比起你写正则的时间要效率得多
If str1 = "" AndAlso str2 = "" Then
和
If str1 = "" OrElse str2 = "" Then