Example of Split function in ASP

xiaoxiao2021-03-06  39

Examples of ASP in Split function: Anonymous Copy from: Site author Hits: 4

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 is saved with the URL value, such as strurl = ftp: // username: password @ server, this is logged in IE What should I do if the URL in the ftp is that if we want to take it out of usrname and password? 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 divide this colon as a split of the split function to split 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 separate the character string to the colon, and the result is saved in Aryreturn (Aryreturn is an 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 & I & I): & Right (Aryreturn (I), LEN (Aryreturn (I)) - 2) &
) Next through the above code, we see the string is split 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 code: strusename = right (Aryreturn (1), Len (Aryreturn (1)) - 2) Take Password's code: '' Take Password We use the Split function, but this returned division is @ Arytemp = SPLIT (Aryreturn (2), @) strpassword = arytemp (0) '' We can remove the server strser = arytemp (1) split can be a character, or a string. Such as: aryreturn = split (ftp:////) Note: 1. Generally, the ASP can not declare the variable. When using the split function, if you want to declare the variable of the return value, you can only With DIM, you cannot use Redim.

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

New Post(0)