?
Solved

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

Posted on 2008-10-05
1
Medium Priority
?
394 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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