Results 1 to 3 of 3

Thread: Convert.ToChar issue...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2004
    Posts
    95

    Convert.ToChar issue...

    I need to convert an array of bytes to a string, but without using Unicode. Just ASCII (base 10 maybe).. so how can I do this? Here's my code, but this spits out a string of unicode characters representing the array, instead of the raw ASCII characters I need.

    VB Code:
    1. Public Shared Function ConvertHashToAscii(ByVal hash() As Byte) As String
    2.  
    3.         Dim sb As New StringBuilder
    4.         Dim number As Byte
    5.  
    6.         For Each number In hash
    7.             sb.Append(Convert.ToChar(number))
    8.         Next
    9.  
    10.         Return sb.ToString
    11.  
    12.     End Function

    Any help, as always, is greatly appreciated.

    Thanks,
    KT

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Try this instead :
    VB Code:
    1. Public Shared Function ConvertHashToAscii(ByVal hash() As Byte) As String
    2.  
    3.         Dim sb As New StringBuilder
    4.         Dim number As Byte
    5.  
    6.         For Each number In hash
    7.             sb.Append(Chr(number)) 'Chr should use ASCii and NOT unicode.
    8.         Next
    9.  
    10.         Return sb.ToString
    11.  
    12.     End Function
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. Public Shared Function ConvertHashToAscii(ByVal hash() As Byte) As String
    2.         Return New System.Text.ASCIIEncoding().GetString(hash)
    3.     End Function
    Last edited by nemaroller; May 13th, 2004 at 05:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width