String function example of ASP
Use a string function to intercept the string, size and other operations.
Function Syntax Function Lenlen (String | VarName) Returns the number of characters within the string, or the number of bytes required to store a variable. Trimtrim (string) Remove the space before and after the string to remove the space in front of the string RTRIMRTRIM (String) Remove the space behind the string to get the midmid (String, Start, Length) starting from the START character of the String string Length's string, if the third parameter is omitted, the string of LEFTLEFT (String, Length) starting from the start character to the string of the string, from the left side of the String string Right (String, Length) from String The string of the string LCaselcase (String) transforming all uppercase letters in the String string into lowercase letters ucaseucse (string) Transformation of all uppercase letters in the String string to uppercase letters strCompstrComp (String1, String2 [ , Compare]) Returns the comparison result of the String1 string and the String2 string, if the two strings are the same, return 0, if it is less than returns -1, if it is greater than, returns 1instrinstr (String1, String2 [, compare]) Return String1 String Position splitsplit (String1, Delimiter [, Count [, start]] in String2 string, split string into one-dimensional array, where Delimiter is used to identify sub-string boundaries according to DELIMITER. If omitted, use space ("") as a separator. The number of sub-strings returned by count, and -1 indicates that all sub-strings are returned. START is 1 to perform text comparison; if it is 0 or omitted to perform binary comparison. ReplaceReplace (Expression, Find, ReplaceWith [, Compare [, Count [, start]]) Returns a string, where specified number of schist (Find) is replaced with another sub-string.
1, the LEN function example:
The following example uses the LEN function to return the number of characters in the string:
DIM mystring
MyString = LEN ("VBScript") 'MyString contains 8.
2, TRIM, LTRIM, RTRIM function example:
The following example uses LTRIM, RTRIM, and TRIM functions to remove spaces, tail spaces, start and tail spaces:
DIM Myvar
MyVAR = LTRIM ("VBScript") 'MyVar contains "VBScript".
Myvar = RTRIM ("VBScript") 'MyVar contains "VBScript".
MyVAR = TRIM ("VBScript") 'MyVar contains "VBScript".
3, MID function example:
The following example uses the MID function to return six characters from the fourth character from the fourth character:
DIM Myvar
Myvar = MID ("VB Scripts IS Fun!", 4, 6) 'MyVar contains "script".
4. Example of the Left function:
The following example uses the LEFT function to return three letters on the left of MyString:
DIM mystring, leftstring
MyString = "vbscript" leftstring = left (mystring, 3) 'Leftstring contains "VBS
5, Right function example:
The following example uses the Right function to return a specified number of characters from the right side of the string:
Dim Anystring, MyStr
Anystring = "Hello World" 'Defines the string.
MyStr = Right (anystring, 1) 'Returns "D".
MYSTR = Right (anyString, 6) 'Returns "World".
MyStr = Right (anystring, 20) 'Returns "Hello World".
6, LCASE function example:
The following example uses the LCase function to convert uppercase letters to lowercase letters:
DIM mystring
DIM LCaseString
MyString = "VBScript"
LcaseString = Lcase (MyString) 'LCaseSString contains "VBScript".
7, ucase function example:
The following example uses the UCase function to return a string of string:
DIM Myword
Myword = ucase ("Hello World") 'Returns "Hello World".
8, Strcomp function example:
The following example uses the Strcomp function to return the result of a string comparison. If the third parameter is 1 to perform text comparison; if the third parameter is 0 or omitted to perform binary comparison.
DIM MyStr1, MyStr2, Mycomp
MyStr1 = "abcd": mystr2 = "abcd" 'defines variables.
Mycomp = strcomp (MySTR1, MySTR2, 1) 'returns 0.
Mycomp = strcomp (mystr1, mystr2, 0) 'returns -1.
Mycomp = strcomp (mystr2, mystr1) 'returns 1.
9, INSTR example:
The following example uses the Instr search string:
Dim searchstring, seechchar, mypos
SearchString = "xxpxxpxxpxxp"???
SearchChar = "p" ??
MyPOS = INSTR (SearchString, SearchChar) Returns 9.
Note: Returns are not a character position in another string that appears in the first time, but the byte position.
10, Split function example:
DIM mystring, myarray, msgmystring = "vbscriptxisxfun!" Myarray = split (mystring, "x", - 1, 1) 'MyArray (0) Contains "VBScript".' MyArray (1) Contains "IS". 'MyArray (2 ) Contains "Fun!". Response.write (MyArray (0))
11, replace function example: