常用ASP自定義函數全集(6)_ASP教程

      編輯Tag賺U幣
      教程Tag:暫無Tag,歡迎添加,賺取U幣!

      推薦:解讀ASP常見錯誤類型大全
      ActiveServerPages,ASP0126(0x80004005)--找不到包含文件 MicrosoftOLEDBProviderforODBCDrivers(0x80040E21)--sql語句出錯(數據類型不匹配或表名(字段名)錯誤或表處于編輯狀態,或表不存在于conn打開的數據庫中) MicrosoftOLEDBProviderforODBCDrivers(0x800

      'UTF8編碼文字將轉換為漢字
      function ConvChinese(x)
          A=split(mid(x,2),"%")
          i=0
          j=0
         for i=0 to ubound(A)
            A(i)=c16to2(A(i))
         next
         for i=0 to ubound(A)-1
           DigS=instr(A(i),"0")
           Unicode=""
           for j=1 to DigS-1
             if j=1 then
               A(i)=right(A(i),len(A(i))-DigS)
               Unicode=Unicode & A(i)
             else
                i=i+1
                A(i)=right(A(i),len(A(i))-2)
                Unicode=Unicode & A(i)
             end if
           next

           if len(c2to16(Unicode))=4 then
              ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
           else
              ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
           end if
         next
      end function

      '二進制代碼轉換為十六進制代碼
      function c2to16(x)
          i=1
          for i=1 to len(x) step 4
             c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
          next
      end function

      '二進制代碼轉換為十進制代碼
      function c2to10(x)
          c2to10=0
          if x="0" then exit function
            i=0
          for i= 0 to len(x) -1
             if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
          next
      end function

      '十六進制代碼轉換為二進制代碼
      function c16to2(x)
           i=0
           for i=1 to len(trim(x))
             tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
             do while len(tempstr)<4
                tempstr="0" & tempstr
             loop
             c16to2=c16to2 & tempstr
          next
      end function

      '十進制代碼轉換為二進制代碼
      function c10to2(x)
          mysign=sgn(x)
          x=abs(x)
          DigS=1
          do
             if x<2^DigS then
               exit do
             else
               DigS=DigS+1
             end if
          loop
          tempnum=x

          i=0
          for i=DigS to 1 step-1
             if tempnum>=2^(i-1) then
                tempnum=tempnum-2^(i-1)
                c10to2=c10to2 & "1"
             else
                c10to2=c10to2 & "0"
             end if
          next
          if mysign=-1 then c10to2="-" & c10to2
      end function
      '-------------------------------
      'GB轉UTF8--將GB編碼文字轉換為UTF8編碼文字
      Function toUTF8(szInput)
           Dim wch, uch, szRet
           Dim x
           Dim nAsc, nAsc2, nAsc3
           '如果輸入參數為空,則退出函數
           If szInput = "" Then
               toUTF8 = szInput
               Exit Function
           End If
           '開始轉換
            For x = 1 To Len(szInput)
               '利用mid函數分拆GB編碼文字
               wch = Mid(szInput, x, 1)
               '利用ascW函數返回每一個GB編碼文字的Unicode字符代碼
               '注:asc函數返回的是ANSI 字符代碼,注意區別
               nAsc = AscW(wch)
               If nAsc < 0 Then nAsc = nAsc + 65536
          
               If (nAsc And &HFF80) = 0 Then
                   szRet = szRet & wch
               Else
                   If (nAsc And &HF000) = 0 Then
                       uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
                       szRet = szRet & uch
                   Else
                      'GB編碼文字的Unicode字符代碼在0800 - FFFF之間采用三字節模版
                       uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
                                   Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
                                   Hex(nAsc And &H3F Or &H80)
                       szRet = szRet & uch
                   End If
               End If
           Next
              
           toUTF8 = szRet
      End Function

      %>

      分享:ASP實現長文章手動分頁的代碼
      % setrecordset1=server.createobject(adodb.recordset) exec=SELECT*FROMnewswhereid=id recordset1.Openexec,conn,1,1 % tablewidth=85%border=0align=centercellpadding=3cellspacing=0 trtd ....... % IfRequest(page)=Then pageNum=0

      共6頁上一頁123456下一頁
      來源:模板無憂//所屬分類:ASP教程/更新時間:2010-04-10
      相關ASP教程