fso| Skills
Next, the following example specifically covers the question of the open method, remember? Under normal circumstances, open the file is to use the FSO. OpenTextFile ("C:\testfile.txt", 1), and the function of parameter 1 is to open the file in read-only mode. This file cannot be written to. What if a file already exists and an append write is required? Simple, the parameter is 8.
What's the use? Oh, Amazon's network story solitaire is so: can Solitaire need to first show the original story, and then add their own stories to write files. One of the most exquisite writing files is the append write. So the following can be achieved.
Second, story. Asp
<%if not request. Form ("nextline") = "" Then
set fso=server.createobject ("Scripting.FileSystemObject")
textfile1=server.mappath ("Story.txt")
set Cnrs=fso. OpenTextFile (textfile1,8)
cnrs. WriteLine (Request.Form ("nextline"))
cnrs. The close
end if
%> story is as follows: <%
set fso=server.createobject (" Scripting.FileSystemObject ")
textfile1=server.mappath (" Story.txt ")
set Cnrs=fso. OpenTextFile (textfile1,1)
while not CNRS. AtEndOfStream
response.write "" & CNRS. Readlinewend
cnrs.close%>
<form method= "POST" action= "story.asp" > Please enter a new line for this story:
<input name= "nextline" type= "text" size= "All" >
<input type= "Submit" value= "submitted" ></form>
The whole is a very simple read information and add information to the mixed use, I believe there is the basis of the previous understanding should not be a problem. Of course, the lack of a story.txt file, inside the beginning of a good story can be.
Debugging
Next, go on, the main focus is to practice some of the use of functions of skills.
1,instr function: Returns the position in which a string appears for the first time in another string.
For example, now look for the first occurrence of the letter "A" in the string "a110b121c119d1861", you can
<script language=vbs>
my_string = "a110b121c119d1861"
A_num = InStr (my_string, "A")
Alert (A_num)
</script>
The position of the same letter "B" can be determined. Here we go. The key: Advance the letter "A" and "B" in the middle of the value "110".
Remember the mid function? The mid function's main function is to return a specified number of characters from a string.
For example, the current "110" should be from the 2nd bit of the string to get 3 units of value.