Solved

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

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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