[vb6.0/vba] "ADODB.Stream"을 이용한 UTF-8 encoding > vb6.0/vba

본문 바로가기

vb6.0/vba

[vb6.0/vba] [vb6.0/vba] "ADODB.Stream"을 이용한 UTF-8 encoding

회원사진
하나를하더라도최선을
2020-02-12 20:49 3,605 0

본문



Public Function UTF8(StringVal As String, Optional SpaceAsPlus As Boolean = True) As String

Dim bytes() As Byte, b As Byte, i As Integer, space As String

If SpaceAsPlus Then space = "+" Else space = "%20"

If Len(StringVal) > 0 Then

With CreateObject("ADODB.Stream")

.Mode = 3 '// adModeReadWrite

.Type = 2 '// adTypeText

.Charset = "UTF-8"

.Open

.WriteText StringVal

.Position = 0

.Type = 1 '// adTypeBinary

.Position = 3 ' skip BOM

bytes = .Read

End With

ReDim result(UBound(bytes)) As String

For i = UBound(bytes) To 0 Step -1

b = bytes(i)

Select Case b

Case 97 To 122, 65 To 90, 48 To 57, 45, 46, 95, 126

result(i) = Chr(b)

Case 32

result(i) = space

Case 0 To 15

result(i) = "%0" & Hex(b)

Case Else

result(i) = "%" & Hex(b)

End Select

Next i

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색