Everyone has encountered some values in a string to take a string? Do you feel that reading or textbooks have a confused split's writing. If you have any questions, please see the explanation of the example below, I believe you will have a certain understanding of this.
Let me introduce the usage of the SPLIT function: return value array = split ("string", "split")
Assume that the variable Strull holds the URL value, such as strurl = "ftp: // username: password @ server", this is the URL form when we log in to the FTP in IE, if we want to take it out of the username and password ,what can we do about it? Of course, there are many ways to solve, where we only describe how to solve with splits. First, we find the split. We have found that there is a colon between UserName and Password, so we use this colon as a "split" of the split function to divide the entire string, and finally reach the purpose of UserName and Password. . The code is as follows: strurl = "ftp: // username: password @ server" Aryreturn = Split (Strurl, ":") So we will split the character series colon, and the result is saved in Aryreturn (Aryreturn is a Array).
Let's take a look at this final result, because the split function ends back to an array, so we mainly show the elements in the array, and to involve some functions related to the number of groups: Isarray () Judging whether the array The function, LBound () takes the subscript of the group, Ubound () takes the subscript of the group.
Response.write ("Return value is an array:" & Isarray (Aryreturn) & "
") for i = lbound (aryreturn) to Ubound (Aryreturn) Response.write ("Elements in Return Value [" & I & "]:" & Right (Aryreturn (i), Len (Aryreturn (I)) - 2) & "
") Next
Through the above code, we see the string into three parts, namely "ftp", "// username", "password @ server". We have to take further processing, I don't have much to say, directly to the code. Take UserName's code: strusename = right (Aryreturn (1), Len (Aryreturn (1)) - 2) Take the password code:
'Take Password We use the SPLIT function, but this split is "@" Arytemp = Split (Aryreturn (2), "@") strpassword = arytemp (0)' We can remove ServersTrServer = Arytemp (1 )
The split can be a character or a string. Such as: aryreturn = split ("ftp: // username: Password @ server," // ") Note: In general, the variable can not be declared in the ASP. When using the Split function, if you want to declare the returned value of the variable Only DIM can only be used, not to use Redim. Although it returns to be an array, it should be used by Redim, but don't do it during the actual use. I don't know what is going on? 2. If you use the split function to split one When there is no split in the string, the entire string is returned, and the result is an array of only one element.
Later, for some characters or part to take a string, as long as you seize the law, you can use Split to make a variety of effects. Write this article, I hope to help everyone, and I hope that the experts can give one or two!