ASP字串编码解码函数
成功志
ASP字串编码解码函数
2012-9-13 ok12

'ASP字串编码解码函数可用于读写cookies前后以防止乱码


  '**************************************************

  '函数名:CodeCookie

  '作 用:Cookie防乱码写入时用

  '参 数:str ---- 字符串

  '返回值:整理后的字符串

  '**************************************************


  Public Function CodeCookie(str)

   If isNumeric(str) Then str=Cstr(str)

   Dim newstr

   newstr=""

   For i=1 To Len(str)

   newstr=newstr & ascw(mid(str,i,1))

   If i<> Len(str) Then newstr= newstr & "a"

   Next

   CodeCookie=newstr

  End Function


 '**************************************************

  '函数名:DecodeCookie

  '作 用:Cookie防乱码读出时用

  '参 数:str ---- 字符串

  '返回值:整理后的字符串  

  '**************************************************

  Public Function DecodeCookie(str)

   DecodeCookie=""

   Dim newstr

   newstr=Split(str,"a")

   For i = LBound(newstr) To UBound(newstr)

   DecodeCookie= DecodeCookie & chrw(newstr(i))

   Next

  End Function

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容