Function to Convert to String of Hex Characters

3 views
Skip to first unread message

Alan

unread,
Nov 20, 2009, 7:42:10 PM11/20/09
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I need to convert an ASCII string to a string of Hex codes
representing the characters. Is there a VB.NET function that does
this, or close to it?

I've searched a lot, but all I find is how to convert ASCII or UTF to
hex bytes, not a string of Hex characters.

Thanks, Alan

Processor Devil

unread,
Nov 23, 2009, 11:40:01 AM11/23/09
to dotnetde...@googlegroups.com
This one is really stupid example, but it really works this way, so why not...
        Public Shared Function ConvertToHex(text As String) As String
            Dim sb As New StringBuilder()
            For Each b As Byte In text
                sb.Append(b.ToString("x"))
            Next
            Return sb.ToString()
        End Function

2009/11/21 Alan <jalan...@verizon.net>
Reply all
Reply to author
Forward
0 new messages