Article Background:
One day, one of my colleagues showed me an article about csdn. Programming Language In the ranking article, I saw that VB is still well ranked. I just said that ASP (VBScript) is really good. As a result, he refuted me and said that ASP is not good and many things are difficult to implement. What do I say, for example? I have developed ASP for a few years and have not found anything that is difficult to implement, unless it is within the scope of a non-scripting language, such as multithreading applications (of course, ASP can also simulate the implementation of multithreading tasks). As a result, he talked about multithreading and encoding conversion. He said that he had spent a lot of energy but had not succeeded in converting the encoding, so he thought ASP was too weak. When we hear this, we will know that his programming background is not solid enough, and his understanding of ASP is also very limited (and later I don't know about several common basic ASP objects, I almost got dizzy. I didn't even use it. I also talked about ASP very weak. It seems that... white growth is big, even "no reason, no say" do not understand! Haha ...), so, I was so angry that I had implemented ASP code interchange that weekend, so that he could see what ASP is, so he looked down on ASP and thought about it! Of course, my research also fills the gaps in the study of encoding conversion in ASP development so far!
Now, let's start with the subject. First, let's take a look at the encoding conversion process. If we want to convert the encoding of a text, we need to know the encoding set corresponding to the current text, then use the corresponding sequence set to read the data. This is the prerequisite for correct encoding conversion (if this step is wrong, the conversion will be a series of garbled characters )! Okay. After finding the current encoding and correctly reading it, we can use the stream object with the destination encoding set to save the content to the specified file, here our encoding conversion is successful!
Next, let's take a look at the specifics of ASP encoding conversion.Code Implementation: Copy code The Code is as follows: 'convert the encoding content to convert the encoding content, cset the destination encoding, and DEST the absolute path of the destination file.
Function transfercharset (content, cset, DEST)
Dim objstream
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. mode = 3
Objstream. charset = cset
Objstream. type = 2
Objstream. Open
Objstream. writetext content
Objstream. Position = 0
Objstream. savetofile DEST, 2
Objstream. Close
Set objstream = nothing
End Function
'Use the corresponding encoding to read the specified content
Function getcontent (PATH)
Dim objstream
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. charset = getcharsetname (PATH)
Objstream. type = 2
Objstream. mode = 3
'Objstream. charset = Code
Objstream. Open
Objstream. loadfromfile path
Objstream. Position = 0
Getcontent = objstream. readtext
Objstream. Close
Set objstream = nothing
End Function
'Get the encoding name of the specified content
Function getcharsetname (PATH)
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1
Objstream. mode = 3
Objstream. Open
Objstream. Position = 0
Objstream. loadfromfile path
Bintou = objstream. Read (2)
If ASCB (midb (Bintou, 1, 1) = & Hef and ASCB (midb (Bintou, 2, 1) = & HBB then
Getcharsetname = "UTF-8"
Elseif ASCB (midb (Bintou, 1, 1) = & HFF and ASCB (midb (Bintou, 2, 1) = & hfe then
Getcharsetname = "Unicode"
Else
Getcharsetname = "gb2312"
End if
Objstream. Close
Set objstream = nothing
End Function
Well, after such a piece of code, our transformation is complete! I hope this article will bring some help and inspiration to ASP fans and other language lovers.
Finally, what I want to say is that it is not difficult to learn and use programming languages. The important thing is to use your own brains and think about how to implement the functions you need, instead of blaming others, the language is too weak.
Well, I wish you all a great deal of programming. I will write about ASP encoding conversion here first, and I will introduce more brilliant original personal articles later. Thank you!