1
汉字转换为UTF-8
2
Function trans()Function trans(str)
3
dim strlen
4
dim conertstr
5
if IsNull(str) then
6
Trans=str
7
else
8
position=1
9
strlen=Len(str)
10
dim j
11
for j=1 to strlen
12
convertstr=convertstr & "&#x" & Hex(AscW(Mid(str,j,1))) & ";"
13
next
14
Trans=convertstr
15
end if
16
end Function
17
18
Function chinese2unicode()function chinese2unicode(Str)
19
dim i
20
dim Str_one
21
dim Str_unicode
22
for i=1 to len(Str)
23
Str_one=Mid(Str,i,1)
24
Str_unicode=Str_unicode&chr(38)
25
Str_unicode=Str_unicode&chr(35)
26
Str_unicode=Str_unicode&chr(120)
27
Str_unicode=Str_unicode& Hex(ascw(Str_one))
28
Str_unicode=Str_unicode&chr(59)
29
next
30
Response.Write Str_unicode
31
end function
32
33
UTF-8 To GB2312
34
35
Function UTF2GB()function UTF2GB(UTFStr)
36
for Dig=1 to len(UTFStr)
37
if mid(UTFStr,Dig,1)="%" then
38
if len(UTFStr) >= Dig+8 then
39
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
40
Dig=Dig+8
41
else
42
GBStr=GBStr & mid(UTFStr,Dig,1)
43
end if
44
else
45
GBStr=GBStr & mid(UTFStr,Dig,1)
46
end if
47
next
48
UTF2GB=GBStr
49
end function
50
51
52
Function ConvChinese()function ConvChinese(x)
53
A=split(mid(x,2),"%")
54
i=0
55
j=0
56
57
for i=0 to ubound(A)
58
A(i)=c16to2(A(i))
59
next
60
61
for i=0 to ubound(A)-1
62
DigS=instr(A(i),"0")
63
Unicode=""
64
for j=1 to DigS-1
65
if j=1 then
66
A(i)=right(A(i),len(A(i))-DigS)
67
Unicode=Unicode & A(i)
68
else
69
i=i+1
70
A(i)=right(A(i),len(A(i))-2)
71
Unicode=Unicode & A(i)
72
end if
73
next
74
75
if len(c2to16(Unicode))=4 then
76
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
77
else
78
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
79
end if
80
next
81
end function
82
83
Function c2to16()function c2to16(x)
84
i=1
85
for i=1 to len(x) step 4
86
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
87
next
88
end function
89
90
Function c2to10()function c2to10(x)
91
c2to10=0
92
if x="0" then exit function
93
i=0
94
for i= 0 to len(x) -1
95
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
96
next
97
end function
98
99
Function c16to2()function c16to2(x)
100
i=0
101
for i=1 to len(trim(x))
102
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
103
do while len(tempstr)<4
104
tempstr="0" & tempstr
105
loop
106
c16to2=c16to2 & tempstr
107
next
108
end function
109
110
Function c10to2()function c10to2(x)
111
mysign=sgn(x)
112
x=abs(x)
113
DigS=1
114
do
115
if x<2^DigS then
116
exit do
117
else
118
DigS=DigS+1
119
end if
120
loop
121
tempnum=x
122
123
i=0
124
for i=DigS to 1 step-1
125
if tempnum>=2^(i-1) then
126
tempnum=tempnum-2^(i-1)
127
c10to2=c10to2 & "1"
128
else
129
c10to2=c10to2 & "0"
130
end if
131
next
132
if mysign=-1 then c10to2="-" & c10to2
133
end function
134

2


3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18


19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35


36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52


53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83


84

85

86

87

88

89

90


91

92

93

94

95

96

97

98

99


100

101

102

103

104

105

106

107

108

109

110


111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134
