Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/04/2007, 10:05
Avatar de dogduck
dogduck
 
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 18 años, 4 meses
Puntos: 19
Re: como convertir a assci o ansi??

http://groups.google.es/group/micros...f3c3fd8182563e
Cita:
Private Const CP_UTF8 = 65001


Private Declare Function MultiByteToWideChar Lib "kernel32" ( _
ByVal CodePage As Long, ByVal dwFlags As Long, _
ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, _
ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long


Public Function sUTF8ToUni(bySrc() As Byte) As String
' Converts a UTF-8 byte array to a Unicode string
Dim lBytes As Long, lNC As Long, lRet As Long


lBytes = UBound(bySrc) - LBound(bySrc) + 1
lNC = lBytes
sUTF8ToUni = String$(lNC, Chr(0))
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bySrc(LBound(bySrc))),
lBytes, StrPtr(sUTF8ToUni), lNC)
sUTF8ToUni = Left$(sUTF8ToUni, lRet)
End Function


Public Sub ConvertUTF8File(sUTF8File As String, sANSIFile As String)
Dim iFile As Integer, bData() As Byte, sData As String, lSize As Long


' Get the incoming data size
lSize = FileLen(sUTF8File)
If lSize > 0 Then
ReDim bData(0 To lSize - 1)


' Read the existing UTF-8 file
iFile = FreeFile()
Open sUTF8File For Binary As #iFile
Get #iFile, , bData
Close #iFile


' Convert all the data to Unicode (all VB Strings are Unicode)
sData = sUTF8ToUni(bData)
Else
sData = ""
End If


' Now write it all out to the ANSI file
iFile = FreeFile()
Open sANSIFile For Output As #iFile
Print #iFile, sData
Close iFile
End Sub
salu2