[vb6.0/vba] ADODB.Stream을 이용한 EUC-KR URL Encode > vb6.0/vba

본문 바로가기

vb6.0/vba

[vb6.0/vba] [vb6.0/vba] ADODB.Stream을 이용한 EUC-KR URL Encode

회원사진
하나를하더라도최선을
2020-05-23 03:14 3,447 0

본문



Public Function URLEncode(ByVal StringVal As String, Optional SpaceAsPlus As Boolean = FalseAs 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 12265 To 9048 To 57454695126
          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
 
    URLEncode = Join(result, "")
  End If
End Function

 



사용법:)

debug.? URLEncode("영화")

결과:)

%EC%98%81%ED%99%94

댓글목록0

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