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

본문
Public Function URLEncode(ByVal StringVal As String, Optional SpaceAsPlus As Boolean = False) 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
    URLEncode = Join(result, "")
  End If
End Function
 
사용법:)
debug.? URLEncode("영화")
결과:)
%EC%98%81%ED%99%94
- 이전글[vb6.0/vba] WinHttp를 이용하여 443포트 통신으로 위키백과(ko.wikipedia.org) 에서 특정 키워드로 검색하여 특정 단어가 있는지 체크하기 20.05.23
 - 다음글[vb6.0/vba] 자바스크립트를 이용한 Escape(Encode) / Unescape(Decode) vb에서 사용하기 20.05.23
 
댓글목록
등록된 댓글이 없습니다.



