我使用了 Microsoft 的 MSDN 示例来从字符串中删除非法字符(用于 mysql 查询)。
但是,如何修改函数以使其不删除字符串中的空格? 例如。输入“Test test”将显示为“Testtest”
Function CleanInput(strIn As String) As String
' Replace invalid characters with empty strings.
Try
Return Regex.Replace(strIn, "[^\w\.@-]", "")
' if we timeout when replacing invalid characters, we should return String.Empty.
Catch e As RegexMatchTimeoutException
Return String.Empty
End Try
End Function
任何其他有用的提示也将受到赞赏
找到的解决方案:在正则表达式字符串中添加\s 解决了我的问题
Return Regex.Replace(strIn, "[^\w\s\.@-]", "")
最佳答案
该函数的实际更新版本如下:
Return Regex.Replace(strIn, "[^\w ]", "")
如果这对您不起作用,请告诉我。
关于mysql - vb.net 删除非法字符 - 但不删除空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37669523/