Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Weird problem on hexadecimal conversion
Message
De
21/08/2006 05:28:22
 
 
À
19/08/2006 18:25:58
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01147042
Message ID:
01147222
Vues:
20
This message has been marked as the solution to the initial question of the thread.
Hi,

Probably should be 'Dim loAscii As Encoding = Encoding.Unicode'
HTH,
Viv

>I have a weird problem when converting some text to hexadecimal and vice versa when using French characters. The method works well with non French characters. Here are the two methods:
>
>
>        ' Convert from string to hexadecimal
>        ' expC1 String
>        Public Function StringToHexadecimal(ByVal tcString As String) As String
>            Dim lcString As String = ""
>            Dim lnCounter As Integer = 0
>            Dim loAscii As Encoding = Encoding.ASCII
>            Dim loBytes As Byte() = loAscii.GetBytes(tcString)
>            For lnCounter = 0 To loBytes.Length - 1
>                lcString = lcString + loBytes(lnCounter).ToString("X2")
>            Next
>            Return lcString
>        End Function
>
>        ' Convert from hexadecimal to string
>        ' expC1 String in hexadecimal
>        Public Function HexadecimalToString(ByVal tcString As String) As String
>            Dim lnCounter As Integer = 0
>            Dim loAscii As Encoding = Encoding.ASCII
>            Dim loBytes((tcString.Length / 2) - 1) As Byte
>            For lnCounter = 0 To (tcString.Length / 2) - 1
>                loBytes(lnCounter) = [Byte].Parse(tcString.Substring(lnCounter * 2, 2), _
>                 Globalization.NumberStyles.HexNumber)
>            Next
>            Return loAscii.GetString(loBytes)
>        End Function
>
>
>If I pass this text:
>
>"Vous êtes déjà dans notre programme d'affiliés."
>
>I obtain:
>
>566F7573203F74657320643F6A3F2064616E73206E6F7472652070726F6772616D6D65206427616666696C693F732E
>
>But, doing the reverse process gives:
>
>"Vous ?tes d?j? dans notre programme d\'affili?s."
>
>There is definitely something wrong here on one or both of the processes. Is there anyone who can find where the problem is?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform