Solved

VB.NET how to replace byte chrs that can't be displayed with "?"

Posted on 2008-10-05
1
375 Views
Last Modified: 2008-10-15


I have a network packet that has some ascii text in it as well as some bytes that cant be displayed in the immediate window or console

what i need is a function that can take this byte string & replace any characters that can't be displayed with "?"

for example chr(0) doesn't show up as anything, there are also other characters that don't show up when written out to the console... as if they don't have a symbol/letter/number/etc associated with it

i guess the function needs to replace anything that doesn't have a chr/num/symbol associated with it
0
Comment
Question by:mcainc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 22647580
The Char type in .net has a shared method (function) called IsControl that maybe is the one you're looking for. This function returns true when a char (or a located character position in a string) is a control (or special) character. So you can transform a string replacing control characters with "?" symbol with the function attached.

Hope this will work for you. Good luck!
Private Function TransformString(ByVal Info As String) As String
    Dim sCopy As String = ""
 
    For Each cChar As Char In Info
        If Char.IsControl(cChar) Then
            sCopy += "?"
        Else
            sCopy += cChar
        End If
    Next
 
    Return sCopy
End Function

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Set arraylist as datatable 2 28
PowerShell: Adding ToGB to a script 4 71
Cannot interpret token '"' at position 10. 3 24
Open telerik datetime picker programmatically 13 42
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question