我如何得到像
这样的字符串'EJ0004','EK0001','EA0001'
来自
之类的字符串在VB.NET中{Emaster.Emp_Code} ='EJ0004'或{Emaster.Emp_Code} ='EK0001'或{Emaster.Emp_Code} ='EA0001'
?
答案 0 :(得分:1)
您可以使用regular expression。
示例:强>
Sub Main
Dim s = "{Emaster.Emp_Code}='EJ0004' OR {Emaster.Emp_Code}='EK0001' OR {Emaster.Emp_Code}='EA0001'"
Dim pattern = "('\w*')"
Dim matches = Regex.Matches(s, pattern)
Dim values = matches.OfType(Of Match).Select(Function(m) m.Value)
For Each v in values
Console.WriteLine(v)
Next
Console.WriteLine(String.Join(",", values))
End Sub
<强>输出:强>
'EJ0004'
'EK0001'
'EA0001'
'EJ0004', 'EK0001', 'EA0001'
答案 1 :(得分:1)
有很多方法可以做到这一点,我在这里提供一个简单的方法:
dim yourString as string = 'This is the variable which holds your initial string
dim newString as string = yourString.replace("{Emaster.Emp_Code}=", "").replace(" OR ",",")
现在newString将保持'EA0001'或者其他什么。 如果你想要它没有''那么做
dim newString as string = yourString.replace("{Emaster.Emp_Code}=", "").replace("'","").replace(" OR ",",")