检测字符串中不可打印的ASCII字符

时间:2020-01-22 12:43:20

标签: vb.net

我正在使用Visual Basic 2010 Express。我需要解析一个带有不可打印字符的字符串。我需要检测ASCII 4(传输结束)。

扫描仪将数据转储到我的应用程序中的TextBox中。循环中,我正在使用:

If Chr(MyString.Chars(counter)) = 4 Then
   MsgBox("Found")
End If

这不是正确的语法,但应该传达我正在尝试做的事情。

1 个答案:

答案 0 :(得分:1)

扫描仪将数据转储到文本框后:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
   TextBox1.Text = "Some chars coming in from " & Chr(4) & " a scanner"
End Sub

enter image description here

尝试这样的事情:

Dim MyString As String = TextBox1.Text

If MyString.Contains(Chr(4)) Then
   MessageBox.Show("Found")
End If

甚至是这样的东西:

Dim MyString As String = TextBox1.Text
Dim counter As Integer = 26

If MyString.Chars(counter) = Chr(4) Then
   MessageBox.Show("Found")
End If