function you have encountered to want to take a string of certain values and not to start? Do you feel that reading or teaching material is confused with the writing of split ... If you have this question, please see below my explanation to the example, I believe you will have a certain understanding of this.
Let me introduce the use of the split function:
Array of return values = Split ("string", "separator")
Suppose the variable strurl holds the URL value, such as strURL = "Ftp://username:password@server", which is the URL form when we log on to FTP in IE. What if we want to take the username and password out of it? Of course there are many ways to solve, here we only introduce the method of split to solve. First, we find the separator. We found that in this string, there is a colon separating them from the username and password, so we split the colon as a "split" of the split function, and finally get the username and password. The code is as follows:
strURL = "Ftp://username:password@server"
Aryreturn = Split (strURL, ":")
So we split the string with a colon, and the split result is saved in the Aryreturn (Aryreturn is an array).
Let's take a look at the final result, because the split function eventually returns an array, so we're basically showing the elements in the array, and we're going to involve some functions related to the array: IsArray () to determine whether the array's functions, LBound () take the subscript of the array, UBound () takes the superscript of the array.
Response.Write ("Return value is an array:" & IsArray (Aryreturn) & "<br>")
For i = LBound (Aryreturn) to UBound (Aryreturn)
Response.Write ("Return the elements in an array of values [" & I &]: "& Right (Aryreturn (i), Len (Aryreturn (i))-2) &" <br> "
Next
Through the above code, we see that the string is divided into three parts, namely: "FTP", "//username", "Password@server". We want to take username and password need further processing, I will not say more, directly to the code.
To take username code:
strUserName = Right (Aryreturn (1), Len (Aryreturn (1))-2)
To take password code:
' Take password we use the Split function again, but this time the delimiter is ' @ '
Arytemp = Split (Aryreturn (2), "@")
strpassword = arytemp (0)
' We can take the server out of the way
strserver = arytemp (1)
A separator can be a character or a string. Such as:
Aryreturn = Split ("Ftp://username:password@server,"//)
Attention:
1. In general, the ASP can not declare variables, use the Split function, if you want to declare the return value of the variable, you can only use dim, but not with ReDim. Although it is said that its return is an array, it should be used ReDim, but in the actual use of the process is not. I don't know what's going on.
2. If the split function is used to split a delimiter that does not exist in a string, the entire string is returned, resulting in an array of only one element.
Something, in order to take a string of certain characters or parts, as long as the grasp of the law, coupled with split can be very good to make a variety of effects. Write this article, I hope to help you learn, but also hope that the road Master can guide twos!