ASP实现GB2312转UTF-8函数
来源:Fris's Blog 时间:2009-02-26 13:08:00
在中文网页中最常见的网页编码就是GB2312和UTF-8了,本文介绍了ASP实现GB2312编码转换为UTF-8编码的函数:
Function U2UTF8(Byval a_iNum)
Dim sResult,sUTF8
Dim iTemp,iHexNum,i
iHexNum = Trim(a_iNum)
If iHexNum = "" Then
Exit Function
End If
sResult = ""
If (iHexNum < 128) Then
sResult = sResult & iHexNum
ElseIf (iHexNum < 2048) Then
sResult = ChrB(&H80 + (iHexNum And &H3F))
iHexNum = iHexNum \ &H40
sResult = ChrB(&HC0 + (iHexNum And &H1F)) & sResult
ElseIf (iHexNum < 65536) Then
sResult = ChrB(&H80 + (iHexNum And &H3F))
iHexNum = iHexNum \ &H40
sResult = ChrB(&H80 + (iHexNum And &H3F)) & sResult
iHexNum = iHexNum \ &H40
sResult = ChrB(&HE0 + (iHexNum And &HF)) & sResult
End If
U2UTF8 = sResult
End Function
Function GB2UTF(Byval a_sStr)
Dim sGB,sResult,sTemp
Dim iLen,iUnicode,iTemp,i
sGB = Trim(a_sStr)
iLen = Len(sGB)
For i = 1 To iLen
sTemp = Mid(sGB,i,1)
iTemp = Asc(sTemp)
If (iTemp>127 or iTemp<0) Then
iUnicode = AscW(sTemp)
If iUnicode<0 Then
iUnicode = iUnicode + 65536
End If
Else
iUnicode = iTemp
End If
sResult = sResult & U2UTF8(iUnicode)
Next
GB2UTF = sResult
End Function
调用方法
Response.BinaryWrite(GB2UTF("asp之家"))
标签:UTF-8,GB2312,asp
0
投稿
猜你喜欢
基于Python实现电影售票系统
2021-02-21 16:26:05
Go事务中止时是否真的结束事务解析
2023-07-07 11:35:35
Python深入学习之上下文管理器
2023-03-27 19:09:43
MSSQL中递归SQL查询语句实例说明-
2011-09-30 11:42:43
vue 自定义指令directive的使用场景
2024-05-13 09:09:08
Jquery.TreeView结合ASP.Net和数据库生成菜单导航条
2024-01-15 01:23:44
Flask模板引擎之Jinja2语法介绍
2021-11-15 21:08:11
javascript给span标签赋值的方法
2023-09-05 21:28:53
PHP children()函数讲解
2023-06-13 04:38:38
python tarfile压缩包操作保姆级教程
2022-03-29 21:38:30
MySQL中触发器入门简单实例与介绍
2024-01-17 15:02:30
Golang检查变量类型的四种方式
2024-04-27 15:26:11
在Infopath中实现数据有效性验证的三种方法
2023-03-06 15:25:31
base href 使用方法详解
2008-05-18 13:27:00
python爬虫 批量下载zabbix文档代码实例
2022-11-07 11:10:29
在CentOS上配置Nginx+Gunicorn+Python+Flask环境的教程
2021-09-04 07:31:23
Python人工智能学习PyTorch实现WGAN示例详解
2022-10-20 18:49:32
javascript 动态插入技术
2009-12-14 20:50:00
通俗讲解python 装饰器
2022-04-30 08:20:47
python中的Elasticsearch操作汇总
2022-01-29 10:44:45