Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

12 Experts available now in Live!

Get 1:1 Help Now