You can perform an automatic replacement (in the TextChanged Event
of the TextBoxes
, as shown below; or just before dealing with the given String
). For example:
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
TextBox1.Text = TextBox1.Text.Replace(ChrW(8220), "")
TextBox1.Text = TextBox1.Text.Replace(ChrW(8221), "")
TextBox1.Text = TextBox1.Text.Replace("""", "")
If (TextBox1.TextLength > 0) Then
TextBox1.Select(TextBox1.TextLength, 1)
End If
End Sub
This code does not allow users to write "
,“
or ”
. The reason for a so complicated code is that dealing with "curvy" double quotes (as the ones in your sample code) is not straightforward: VB.NET considers them as normal double quotes in most of the situations, but this does not happen immediately (for example, while dealing with the inputs in the code above) and thus you have to consider all the eventualities. Here you have an interested link on this matter.