Research and implementation of ASP code-application techniques

Source: Internet
Author: User
Tags what is asp
Article background:
One day, a colleague of mine showed me a csdn on the list of programming languages, in which I saw VB still ranked very well, and I said, ASP (VBScript) is really pretty good. As a result, he contradicted me, saying that the ASP is not good, many things difficult to achieve. What do I say, like, something? I developed a few years of ASP did not find anything difficult to implement, unless it is within the scope of the non-scripting language, such as multi-threaded applications (of course, ASP can also simulate the implementation of multithreaded tasks) and so on. As a result, he said what multithreading, as well as coding conversion, said that he had to transform the coding cost a lot of energy but did not succeed, so that the ASP is too weak. Hearing this, we know that his programming is not solid enough, and the ASP is very limited to know (and later said that their own ASP several commonly used basic objects do not know, also did not use, I almost was gas fainted-even this has not been used, but also talk to me ASP very weak, it seems ... White long big, even "no basis, no voice" do not understand! Oh... ), so, I was in a rage, in that weekend to the ASP code to achieve the problem, let him see what is ASP, unexpectedly so look at ASP, think of the fire big! Of course, my research also fills up the gap in the research of coding conversion in ASP development so far!

Now, let's get to the point where, first, we'll look at the code conversion process, a piece of text encoding if you want to convert, we need to know the current text of the corresponding coding set, and then use the corresponding encoding set to read, which is the premise of the correct code conversion (if this step is wrong, then the conversion will be a series of garbled)! OK, the right current code, and read it correctly, we can use the set target code stream object to save this content to the specified file, where our code conversion is successful!
Let's take a look at the specific code implementation of ASP encoding conversion:
Copy Code code as follows:

' Conversion encoding content to convert encoded contents, Cset target encoding, dest target file absolute path
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
' reads the specified content with the corresponding encoding
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
' Gets the encoded 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 conversion work is done! I hope this article will give some help and inspiration to the ASP enthusiasts as well as other language enthusiasts.
Finally, I would like to say that the programming language is not difficult to learn and use, it is important to their own brains, think about their own needs of the function how to achieve, rather than complaining, said the language is too weak and so on.
Well, I wish you all programming and happy, about the ASP code conversion first written here, I will also introduce more wonderful personal original articles, thank you!
Related Article

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.