Implement Split by examples

zhaozj2021-02-16  132

http://www.it365cn.com/bbs/topic.asp?topicid=1268

Author: Shuai frog was originally published in: Classic Forum (to achieve understanding split by way of example) copyright Shuai frog all, if quoted, please indicate the relevant information. Have you 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. For example, I want to get a username and password (server, etc.) value in an FTP (using IE when ftp is ftp). Here is my solution: set the URL for the URL value, here: url = ftp: // username: password @ server, please pay attention to the rules of this sentence, I think everyone knows the law in this URL. Let's be ":": ftp, // username, password @ server first distinguish between the part of this URL in all parts of the ":": ftp, // username, password @ server first uses split (URL, ":") below Specific code:

Parts = split (URL, ":") 'At this time, Parts has three parts, Parts (0) = ftp, parts (1) = // username, Parts (2) = password @ Server' Next exclaimed unused Information 'Due to only use Username, it is useless in which parts (0) is useless, it is not quoted directly! NewName = Replace (Parts (1), "//", "" "remove // ​​symbol, because this is not the content in the username 'The newname at this time is the username.

The above is the code that only takes the username. If you want to take a password again, you can refer to the following.

'Since the username is part of Parts (2), and contains information, if the server is not allowed, then: newpass = left (parts (2), INSTR (Parts (2), "@") - 1)' Take the value before @. NewPass at this time is password

The above code is the code of the server address, if you have a server, it is also very simple.

NewParts = Split (Parts (2), "@") 'This time newparts is divided into two parts: newParts (0) is a password, that is, password; newparts (1), the server address, the server' If you want to output your password, Direct Response.Write NewParts (0) is OK, the server is newparts (1)

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 everyone can give you two!

转载请注明原文地址:https://www.9cbs.com/read-8633.html

New Post(0)