Results 1 to 2 of 2

Thread: utf-8 string converter

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2010
    Posts
    35

    Angry utf-8 string converter

    Hi, I need some about converting utf-8 string to ascii and hex. suppose i have some arabic character in a richtextbox how to convert it to hex or ascii. Please someone help me about this

  2. #2
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: utf-8 string converter

    I honestly dont know if this will help but when I need to convert my string from vb6 to a utf 8 string I do the following. With some modification it might do what you need it to do

    Code:
    Public Function ConvertStringToUtf8String(ByRef strText As String) As String
    
        Dim objStream As ADODB.Stream
        Dim Data() As Byte
        Dim strUTF8String As String
        Dim i As Long
        
        ' init stream
        Set objStream = New ADODB.Stream
        objStream.Charset = "utf-8"
        objStream.Mode = adModeReadWrite
        objStream.Type = adTypeText
        objStream.Open
        
        ' write bytes into stream
        objStream.WriteText strText
        objStream.Flush
        
        ' rewind stream and read text
        objStream.Position = 0
        objStream.Type = adTypeBinary
        objStream.Read 3 ' skip first 3 bytes as this is the utf-8 marker
        Data = objStream.Read()
        
        ' close up and return
        objStream.Close
        
        'Convert back to ascii
        For i = 0 To UBound(Data)
            strUTF8String = strUTF8String & Chr(Data(i))
        Next i
        ConvertStringToUtf8String = strUTF8String
    
    End Function
    Sorry that I cant be much more help
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

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