СообЧа > База Знаний > Программирование > Visual Basic

Вопрос

Какие есть Api-функции для перекодировки текстов из одной кодовой страницы другую?

Ответ

'Перекодировка символов

Public Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage
As Long, ByVal dwFlags As Long, _
ByVal lpWideCharStr As String, ByVal cchWideChar As Long, ByVal
lpMultiByteStr As String, ByVal cchMultiByte As Long, ByVal lpDefaultChar As
String, ByVal lpUsedDefaultChar As Long) As Long
Public Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage
As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As String, ByVal
cchMultiByte As Long, ByVal lpWideCharStr As String, ByVal cchWideChar As
Long) As Long
Public Const WC_COMPOSITECHECK = &H200
Public Const WC_DEFAULTCHAR = &H40
Public Const WC_DISCARDNS = &H10
Public Const WC_SEPCHARS = &H20
Public Const CP_ACP = 0
Public Const CP_OEMCP = 1
Public Const CP_MACCP = 2
Public Const CP_THREAD_ACP = 3
Public Const CP_SYMBOL = 42
Public Const CP_UTF7 = 65000
Public Const CP_UTF8 = 65001
Public Const MB_PRECOMPOSED = &H1
Public Const MB_COMPOSITE = &H2
Public Const MB_USEGLYPHCHARS = &H4
Public Const MB_ERR_INVALID_CHARS = &H8


'Функция перекодировки

Public Function Convert(ByVal strSrc As String, ByVal nFromCP As Long, ByVal
nToCP As Long) As String
Dim nLen As Long
Dim strDst As String
Dim strRet As String
Dim nRet As Long
nLen = Len(strSrc)
strDst = String(nLen * 2, Chr(0))
strRet = String(nLen * 2, Chr(0))
nRet = MultiByteToWideChar(nFromCP, MB_PRECOMPOSED, strSrc, nLen, strDst,
nLen)
nRet = WideCharToMultiByte(nToCP, 0, strDst, nRet, strRet, nLen * 2, ByVal
0, 0)
Convert = Left(strRet, nRet)
End Function


Сурменок Павел



Copyright © 2000-2004 Сообщество Чайников
Контактная информация