‘-------------------------------------------------
' Function name: gb2utf_file
' Function: Use ADODB.stream object to convert GB2312 format text file to UTF-8 format
‘----------------------------------------------------
Function Gb2utf_file (Utffilename)
Dim gb2utf_1,gb2utf_2,gb2utf_array,gb2utf_i
Gb2utf_1=loadfile (Utffilename, "GB2312")
Gb2utf_array=split (GB2UTF_1,CHR) &CHR (10))
If InStr (Ucase (Gb2utf_array (0)), "language=") >0 and InStr (Ucase (Gb2utf_array (0)), "codepage=") >0 and InStr ( Ucase (Gb2utf_array (0)), "936") >0 Then
Gb2utf_array (0) = "<% @LANGUAGE =" "VBSCRIPT" "codepage=" "65001" "%" & ">"
End If
For gb2utf_i=0 to UBound (Gb2utf_array)
If InStr (Lcase (Gb2utf_array (gb2utf_i)), "http-equiv=") >0 and InStr (Lcase (Gb2utf_array (gb2utf_i)), "Content-type" ) >0 and InStr (Lcase (Gb2utf_array (gb2utf_i)), "content=") >0 and InStr (Lcase (Gb2utf_array (gb2utf_i)), "text/html ;") >0 and InStr (Lcase (Gb2utf_array (gb2utf_i)), "charset=gb2312") >0 Then
Gb2utf_array (gb2utf_i) = "<meta http-equiv=" "Content-type" "content=" "text/html; Charset=utf-8 "" > "
End if
Gb2utf_2=gb2utf_2&gb2utf_array (gb2utf_i) &CHR (+) &CHR (10)
Next
SaveToFile gb2utf_2,utffilename, "UTF-8"
End Function
‘-------------------------------------------------
' Function name: LoadFile
' Function: Use ADODB.stream object to read text file
' CharSet parameter is Text format: UTF-8 format or GB2312 format
‘----------------------------------------------------
Function LoadFile (ByVal file,charset)
Dim objstream
On Error Resume Next
Set objstream = Server.CreateObject ("ADODB. Stream ")
If err.number=-2147221005 Then
Response.Write "<div align= ' center ' > Unfortunately, your host does not support ADODB.stream and cannot use this program </div>"
Err.Clear
Response.End
End If
With Objstream
. Type = 2
. Mode = 3
. Open
. LoadFromFile Server.MapPath (File)
If Err.number<>0 Then
Response.Write "<div align= ' center ' > File <font color= ' #ff0000 ' > &File& ' </font> cannot be opened, Please check if there is!</font></div> "
Err.Clear
Response.End
End If
. Charset = Charset
. Position = 2
LoadFile =. ReadText
. Close
End with
Set objstream = Nothing
End Function
‘-------------------------------------------------
' Function name: SaveToFile
' Function: Use ADODB.stream objects to store text files
' CharSet parameter is Text format: UTF-8 format or GB2312 format
‘----------------------------------------------------
Sub SaveToFile (ByVal strbody,byval file,charset)
Dim objstream
On Error Resume Next
Set objstream = Server.CreateObject ("ADODB. Stream ")
If err.number=-2147221005 Then
Response.Write "<div align= ' center ' > Unfortunately, your host does not support ADODB.stream and cannot use this program </div>"
Err.Clear
Response.End
End If
With Objstream
. Type = 2
. Open
. Charset = Charset
. Position = Objstream.size
. WRITETEXT = Strbody
. SaveToFile Server.MapPath (File), 2
. Close
End with
Set objstream = Nothing
End Sub
Convert asp:gb2312 Format text file to UTF-8 format