Solved

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

Posted on 2008-10-05
1
366 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

929 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now