Convert asp:gb2312 Format text file to UTF-8 format

Source: Internet
Author: User

‘-------------------------------------------------
' 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) &AMP;CHR (+) &AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.