메뉴 건너뛰기

Dev tips

ASP URLDecode, URLEncode Ansi, UTF-8 모음

taknim 2011.04.02 21:20 조회 수 : 8570 추천:1714

http://blog.naver.com/falconer00/80010885656Function toUTF8(szSource)
        Dim szChar
        Dim WideChar
        Dim nLength
        Dim i

        toUTF8 = ""
        nLength = Len(szSource)
        For i = 1 To nLength
                szChar = Mid(szSource, i, 1)

                If Asc(szChar) < 0 Then
                        WideChar = CLng(AscB(MidB(szChar, 2, 1))) * 256 + AscB(MidB(szChar, 1, 1))

                        If (WideChar And &HFF80) = 0 Then
                                toUTF8 = toUTF8 & "%" & Hex(WideChar)
                        ElseIf (WideChar And &HF000) = 0 Then
                                toUTF8 = toUTF8 & _
                                          "%" & Hex(CInt((WideChar And &HFFC0) / 64) Or &HC0) & _
                                          "%" & Hex(WideChar And &H3F Or &H80)
                        Else
                                toUTF8 = toUTF8 & _
                                          "%" & Hex(CInt((WideChar And &HF000) / 4096) Or &HE0) & _
                                          "%" & Hex(CInt((WideChar And &HFFC0) / 64) And &H3F Or &H80) & _
                                          "%" & Hex(WideChar And &H3F Or &H80)
                        End If
                Else
                        toUTF8 = toUTF8 + szChar
                End If
        Next
        Exit Function
End Function

Function URLDecode(Expression)
        Dim strSource, strTemp, strResult, strchr
        Dim lngPos, AddNum, IFKor        
        strSource = Replace(Expression, "+", " ")
        For lngPos = 1 To Len(strSource)
                AddNum        = 2
                strTemp = Mid(strSource, lngPos, 1)
                If strTemp = "%" Then
                        If lngPos + AddNum < Len(strSource) + 1 Then
                                strchr = CInt("&H" & Mid(strSource, lngPos + 1, AddNum))
                                If strchr > 130 Then
                                        AddNum = 5
                                        IFKor = Mid(strSource, lngPos + 1, AddNum)
                                        IFKor = Replace(IFKor, "%", "")
                                        strchr = CInt("&H" & IFKor )
                                End If
                                strResult = strResult & Chr(strchr)
                                lngPos        = lngPos + AddNum
                        End If
                Else
                        strResult = strResult & strTemp
                End If
        Next        
        URLDecode = strResult
End Function

Function UrlDecode_GBToUtf8(ByVal str)
        Dim B,ub
        Dim UtfB
        Dim UtfB1, UtfB2, UtfB3
        Dim i, n, s
        n=0
        ub=0
        For i = 1 To Len(str)
                B=Mid(str, i, 1)
                Select Case B
                        Case "+"
                                s=s & " "
                        Case "%"
                                ub=Mid(str, i + 1, 2)
                                UtfB = CInt("&H" & ub)
                                If UtfB<128 Then
                                        i=i+2
                                        s=s & ChrW(UtfB)
                                Else
                                        UtfB1=(UtfB And &H0F) * &H1000
                                        UtfB2=(CInt("&H" & Mid(str, i + 4, 2)) And &H3F) * &H40
                                        UtfB3=CInt("&H" & Mid(str, i + 7, 2)) And &H3F
                                        s=s & ChrW(UtfB1 Or UtfB2 Or UtfB3)
                                        i=i+8
                                End If
                        Case Else
                                s=s & B
                End Select
        Next
        UrlDecode_GBToUtf8 = s
End Function

--------------------------------------------------------------------------------
runat="server" 으로 함수 구현
<script language="javascript" runat="server">
        function URLDecode(v) {
                return decodeURI(v);
        }
        function URLEncode(v) {
                return encodeURI(v);
        }
</script>
번호 제목 글쓴이 날짜 조회 수
393 [암호화] hash 관련 함수들... taknim 2011.12.20 6614
392 각 브라우저 작업표시줄 탭 미리보기 설정 (Aero Peek 설정) taknim 2011.12.15 7986
391 html에서 엑셀 파일 출력시 해당 컬럼을 텍스트 형식으로 지정 taknim 2011.12.11 8330
390 Gmail 주소 무한대 or 특수기호 무시 taknim 2011.12.10 7496
389 [js] showModalDialog Method taknim 2011.12.05 10083
388 나이 계산 taknim 2011.11.28 7643
387 [js & php] 비밀번호 유효성 체크 - 연속 문자, 같은 문자 taknim 2011.11.09 28407
386 [윈7] 윈7 로그온 화면(잠금 화면) 바꾸기 taknim 2011.10.20 6594
385 [vi] 단어 치환 vi replace taknim 2011.10.10 6161
384 [오라클] 프로시저 확인하기 taknim 2011.10.04 8078
383 navigator.userAgent 정리 taknim 2011.07.06 6613
382 캠핑장 안내 사이트 taknim 2011.06.13 6334
381 [jQuery] 팝업창이나 하위프레임에서 상위 객체를 셀렉트 taknim 2011.06.07 8271
380 키보드 Alt/Ctrl -> 한영전환 레지스트리 [1] file taknim 2011.06.07 7209
379 VBScript Language Reference taknim 2011.05.25 6333
378 [기타] 트위터, 페이스북을 이용한 링크 공유하기 taknim 2011.05.25 13594
377 유용한 ASP 관련 사이트 - w3schools.com taknim 2011.05.10 6472
» URLDecode, URLEncode Ansi, UTF-8 모음 taknim 2011.04.02 8570
375 UTF-8에서 URLEncode, URLDecode 구현 taknim 2011.04.02 6759
374 Ansi(euc-kr, euckr)에서 URLEncode, URLDecode 구현 taknim 2011.04.02 8628