Vb.net 删除字符串中的特定字符

Vb.net 删除字符串中的特定字符,vb.net,special-characters,Vb.net,Special Characters,我有一个代码来检查字符串中是否有特殊字符。如果检测到字符,它将仅删除字符并继续检查。或者如果你有更简单的方法,请帮助我。多谢各位 Public Function IsThereAnySpecialCharacter(ByVal str As String) As Integer Dim illegalChars As Char() = "~`|@#$^*{}'[]""_<>\".ToCharArray() Dim count As Integer

我有一个代码来检查字符串中是否有特殊字符。如果检测到字符,它将仅删除字符并继续检查。或者如果你有更简单的方法,请帮助我。多谢各位

Public Function IsThereAnySpecialCharacter(ByVal str As String) As Integer
        Dim illegalChars As Char() = "~`|@#$^*{}'[]""_<>\".ToCharArray()
        Dim count As Integer
        Try
            count = 0
            For Each ch As Char In str ' to check whether special character exist in a string
                If Not Array.IndexOf(illegalChars, ch) = -1 Then
                    xxxxxxxxxxxxxxxxx ' I want to remove the chars here
                    count = count + 1
                End If
            Next
            Return count
        Catch ex As Exception
            strErrMsg = "Oops! Something is wrong with verify special characters at IsThereAnySpecialCharacter"
            MessageBox.Show(strErrMsg & vbCrLf & "Err: " & ex.Message)
        End Try
    End Function
Public Function IsThereAnySpecialCharacter(ByVal str As String) As Integer
    Dim illegalChars As Char() = "~`|@#$^*{}'[]""_<>\".ToCharArray()

    Try
        For Each ch As Char In illegalChars
            str = str.Replace(ch, "")
        Next
        MsgBox(str)
    Catch ex As Exception
        strErrMsg = "Oops! Something is wrong with verify special characters at IsThereAnySpecialCharacter"
        MessageBox.Show(strErrMsg & vbCrLf & "Err: " & ex.Message)
    End Try
    Return 0
End Function