NaN
NaN

Reputation: 567

Detect Unprintable ASCII Characters in String

I'm using Visual Basic 2010 Express. I need to parse a string with unprintable characters in it. I need to detect ASCII 4 (End of Trans).

A scanner dumps data into a TextBox in my app. In a loop, I am using:

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

This is not the correct syntax but should convey what I'm trying to do.

Upvotes: 0

Views: 627

Answers (1)

Brian M Stafford
Brian M Stafford

Reputation: 8868

After the scanner dumps the data into a textbox:

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

Try something like this:

Dim MyString As String = TextBox1.Text

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

Or even something like this:

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

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

Upvotes: 1

Related Questions