CAFE

vb6 api

[VB 6.0] charset utf-8 형식으로 텍스트 변경시 예제

작성자프링글스|작성시간12.07.09|조회수1,911 목록 댓글 0


출처 : 데브피아


Option Explicit

Private Declare Function WideCharToMultiByte Lib "kernel32" ( _
ByVal CodePage As Long, ByVal dwFlags As Long, _
lpWideCharStr As Any, ByVal cchWideChar As Long, _
lpMultiByteStr As Any, ByVal cchMultiByte As Long, _
ByVal lpDefaultChar As Long, lpUsedDefaultChar As Long) As Long

Private Sub Command1_Click()
Dim Test As String, UTF8Bytes() As Byte
Test = Text1 'The Euro-Sign
'Print Test, Len(Test)


W2UTF8 Test, UTF8Bytes
Test = HexEncode(UTF8Bytes) 'store the result in our Test-Var
'Print Test, Len(Test) / 3 'Len is 8 (Euro-Sign needs 3 UTF8-Bytes)
Text2 = Test
End Sub

Function W2UTF8(W As String, UTF8() As Byte) As Long
Dim Bytes&

If LenB(W) = 0 Then Exit Function
ReDim UTF8(LenB(W) + Len(Text1.Text))
Bytes = WideCharToMultiByte(65001, 0, ByVal StrPtr(W), Len(W), _
UTF8(0), UBound(UTF8), 0, ByVal 0&)

ReDim Preserve UTF8(Bytes - 1)
W2UTF8 = Bytes
End Function

Function HexEncode(B() As Byte)
Dim i&, HexArr() As String
ReDim HexArr(UBound(B))
For i = 0 To UBound(B)
HexArr(i) = Right$("0" & Hex$(B(i)), 2)
Next i
HexEncode = "%" & Join(HexArr, "%")
End Function

 


Private Sub Form_Load()
Text1 = ""
Text2 = ""
End Sub


다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼