我使用VB.NET编写winforms应用程序,如何使用正则表达式删除字符串中"["和"]"之间的空格?
例如,对于一个字符串
"[Product Name] Like '%Dragon Ball%' AND [Product Type] Like '%Toy%'"
Run Code Online (Sandbox Code Playgroud)
我想要结果
"[ProductName] Like '%Dragon Ball%' AND [ProductType] Like '%Toy%'"
Run Code Online (Sandbox Code Playgroud)
我尝试过这个,但它不起作用:
Public Function RemoveSpaceInFieldNames(ByVal expression As String) As String
Dim regex As RegularExpressions.Regex = New
RegularExpressions.Regex(String.Format("\{0}\s*\{1}", "[", "]"))
Return regex.Replace(expression, String.Empty)
End Function
Run Code Online (Sandbox Code Playgroud)