-3

我如何得到字符串

'EJ0004','EK0001','EA0001'

像字符串一样

{Emaster.Emp_Code}='EJ0004' 或 {Emaster.Emp_Code}='EK0001' 或 {Emaster.Emp_Code}='EA0001'

在 VB.NET 中?

4

2 回答 2

1

您可以使用正则表达式


例子:

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'

于 2012-12-10T10:05:32.230 回答
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 ",",")
于 2012-12-10T10:06:45.493 回答