标题:[求助]关于字符转换……
只看楼主
半点心
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-12-17
 问题点数:0 回复次数:5 
[求助]关于字符转换……
请问如何将字符转换成UTF-8、十六进制、或二进制格式??

VB中自带这样的函数吗??

中英文用标符的处理方法也是一样吗??

望高手详细指教!!谢!!
搜索更多相关主题的帖子: 字符 
2005-03-26 21:53
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 
UTF-8 和 16进制、二进制 怎么扯到一块了?

天津网站建设 http://www./
2005-03-26 23:35
半点心
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2004-12-17
得分:0 

我的意思是分两个。

1)。GB2312 转UTF-8 UTF-8还原GB2312 它们转换及还原的函数是怎样??

2)如以下两个,是用字符转换工具按[十六进制]转出来的。怎么变成这样??

编程论坛=0x7F16,0x7A0B,0x8BBA,0x575B,

0123456789=0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,

2005-03-27 10:14
leon2
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:731
专家分:0
注 册:2005-3-18
得分:0 
用 Hex 函数可以转换成十六进制数。
2005-03-27 22:34
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

utf-8-->gb2312函数

<% Function Utf8_Gb2312(Searchstring) Dim Seachchar1, Seachchar2, MyPos1, MyPos2, string1, string2, i, Output_content Seachchar1 = "&#x" Seachchar2 = ";" While InStr(Searchstring, "&#x") <> 0 i = i + 1 '定义i MyPos1 = InStr(Searchstring, Seachchar1) + Len(Seachchar1) string1 = Left(Searchstring, MyPos1 - 1) Searchstring = Replace(Searchstring, string1, "", 1, 1) MyPos2 = InStr(Searchstring, Seachchar2) - Len(Seachchar2) string2 = Left(Searchstring, MyPos2 + Len(Seachchar2) - 1) Searchstring = Replace(Searchstring, string2, "", 1, 1) Output_content = Output_content + ChrW(CInt("&H" & string2)) Wend Utf8_Gb2312 = Output_content End Function %>

[此贴子已经被作者于2005-3-28 8:35:49编辑过]


天津网站建设 http://www./
2005-03-28 08:33
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) &gt;= Dig+8 then
GBStr=GBStr &amp; ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr &amp; mid(UTFStr,Dig,1)
end if
else
GBStr=GBStr &amp; mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end function

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 &amp; A(i)
else
i=i+1
A(i)=right(A(i),len(A(i))-2)
Unicode=Unicode &amp; A(i)
end if
next

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

function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 &amp; 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("&amp;h" &amp; mid(x,i,1))))
do while len(tempstr)&lt;4
tempstr="0" &amp; tempstr
loop
c16to2=c16to2 &amp; tempstr
next
end function

function c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x&lt;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&gt;=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 &amp; "1"
else
c10to2=c10to2 &amp; "0"
end if
next
if mysign=-1 then c10to2="-" &amp; c10to2
end function
%&gt;

[此贴子已经被作者于2005-3-28 8:43:22编辑过]



天津网站建设 http://www./
2005-03-28 08:41



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-14124-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.241572 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved