An example of Split function in ASP

Source: Internet
Author: User
Have you ever encountered the need to take a string of some 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 out the server by the way.
strserver = arytemp (1)
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.