To realize the understanding of split by example

Source: Internet
Author: User
Tags ftp string split
Author: Handsome Frog


was originally published in: The Classic forum (through an example to achieve split understanding)


Copyright Handsome Frog All, if there are references, please indicate the relevant information.





have you ever encountered the need to take some value in a string and not be sure? 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.





For example, I would like to get an FTP username and password (server, etc.) value (ie when FTP or from the table to remove the value of FTP).


Below is my solution:


set URL to receive the URL value, here refers to: Url=ftp://username:password@server, please pay attention to the law of this sentence


I think we all see the rules of this URL, that is, the various parts are ":" to the district divided into three parts, namely: FTP,//username, Password@server


first distinguishes the various parts of the URL, using split (URL, ":")


The following is the specific code:











parts = Split (URL, ":") ' Parts there are three parts at this time, parts (0) =ftp,parts (1) =//username,parts (2) =password@server ' then remove the useless information ' Because only take username, so parts (0) and parts (2) are useless, directly do not quote! Newname=replace (Parts (1), "//", "") ' remove//symbol, because this is not username content ' at this time the newname is both user name.








above is to take the user name code, if you want to take the password again, you can refer to the following.


' Because the username is in parts (2) and contains information about the server, if the server is not taken, then: Newpass = Left (Parts (2), InStr (Parts (2), "@")-1) ' value to the number of digits before @. At this point the newpass is taken as the password








The above code is not to take the server address code, if you have access to the server, in fact, is also very simple


Newparts=split (Parts (2), "@") ' At this point the newparts is divided into two parts: newparts (0) is the password, that is, password;newparts (1) is the server address, If the server is to output the password, Direct Response.Write newparts (0) on it, the server newparts (1)








something, 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 we can guide twos!








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.