The same article I have sent to the blue ideal: http://bbs.blueidea.com/thread-3060231-1-1.html
Original function Source: http://www.blueidea.com/tech/program/2006/3538.asp
Thank the author for sending out this function, but found that this function has a small error:
If the string that needs to be converted is a Chinese character, no problem. However, if there is a number or letter in the middle of the time will be truncated, and not get the correct results.
For example: Gb2utf ("Chinese") can get the correct conversion.
But: Gb2utf ("Chinese 3chinese!") You'll get "Chinese 5".
Not only is truncated, but the first number also does not correspond.
It's a small mistake, but it can be misleading for newbies.
In order to stop everyone from wasting time looking for errors, the wrong version and the correct version are pasted so that learners can compare them.
there is an incorrect version of the online epidemic:
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 < +) Then Sresult = Sresult & iHe Xnum ElseIf (Ihexnum < 2048) Then Sresult = ChrB (&h80 + (Ihexnum and &h3f)) Ihexnum = Ihexn
Um \ &h40 sresult = ChrB (&hc0 + (Ihexnum and &h1f)) & Sresult ElseIf (Ihexnum < 65536) Then Sresult = ChrB (&h80 + (Ihexnum and &h3f)) Ihexnum = ihexnum \ &h40 sresult = ChrB (&am P H80 + (Ihexnum and &h3f)) & sresult Ihexnum = ihexnum \ &h40 sresult = ChrB (&he0 + (ihexnu M and &HF)) & Sresult end If U2utf8 = Sresult End Function function Gb2utf (Byval a_sstr) Dim sgb,sres Ult,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 iunic
Ode<0 then Iunicode = Iunicode + 65536 End If Else iunicode = iTemp End If Sresult = Sresult & U2utf8 (iunicode) Next Gb2utf = Sresult End Function Response.Write
(Gb2utf ("Ghost Butterfly")) ' can get the correct result Response.Write (Gb2utf ("Pluto 308641836")) ' Get: Hades Butterfly 5, the result is wrong.
modified version:
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 < +) Then Sresult = Sresult & Chr B (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 = Ch RB (&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 Di
M 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 = i Temp end If Sresult = Sresult & U2utf8 (iunicode) Next Gb2utf = Sresult End Function RESPONSE.W
Rite (Gb2utf ("Ghost Butterfly")) ' can get the correct result Response.Write (Gb2utf ("Pluto 308641836") ' Get: 308641836, the result is no longer truncated!
This code is for study only.
Posted By: Hades May 11, 2012