‘######################################################
1. ASC (x), CHR (x): Convert character code
[Format]:
P=ASC (x) a character code that returns the first character of the string X
P=CHR (x) returns a character code equal to X
[Example]:
(1) P=CHR (65)
' Output character a because the ASCII code of A is equal to 65
(2) P=ASC ("A")
' Output 65
‘######################################################
2. Len (x): Calculates the length of the string X
[Format]:
P=len (X)
[Description]:
The empty string length is 0, the space character is also counted as a char, while a Chinese character occupies 2 Bytes, but it is also counted as a char.
[Example]:
(1) Make x= "" (Empty string)
Len (X) output is 0
(2) Make x= "ABCD"
Len (X) output is 4
(3) Make x= "VB Course"
Len (X) output is 4
‘######################################################
3. Mid (x) function: Read the middle character of the string X
[Format]:
P=mid (X,n)
Reads from the nth character of X, reading all subsequent characters.
P=mid (X,N,M)
Reads from the nth character of X, reading the following m characters.
[Example]:
(1) x= "ABCDEFG"
P=mid (x,5)
The result is: p= "EFG"
(2) x= "ABCDEFG"
P=mid (x,2,4)
The result is p= "BCDE"
‘######################################################
4. Replace: Replacing some specific strings in a string with a different string
[Format]:
P=replace (X,s,r)
[Description]: Replace string s in string X with string R and return.
[Example]:
X= "VB is very good"
P=replace (X,good,nice)
Output: p= "VB is very nice"
‘######################################################
5. StrReverse: Reverse String
[Format]:
P=strreverse (X)
[Description]:
Returns the string after the X argument is reversed
[Example]:
(1) x= "ABC"
P=strreverse (X)
Output result: p= "CBA"
6. Ucase (x), Lcase (x): Convert the case of the English alphabet
[Format]:
P=lcase (X)
' Convert uppercase letters in the X string to lowercase
P=ucase (X)
' Converts lowercase letters in the X string to uppercase
[Note]: In addition to the English alphabet, no other characters or Chinese text will be affected.
[Example]:
(1) Make x= "VB and VC"
Then the result of LCase (x) is "VB and VC", the result of Ucase (x) is "VB and VC"
7. InStr function: Finding a string
[Format]:
P=instr (x, y)
Find where y appears from the first character of X
P=instr (N,x,y)
Find where y appears from the nth character X
[Description]:
(1) If Y is found in X, the return value is the position where the first character of y appears in X.
(2) InStr (x, y) is equivalent to INSTR (1,x,y).
(3) returns 0 if the string length, or x is an empty string, or if Y is not found in X.
(4) If Y is an empty string, 0 is returned.
----------------------------------------------------------------------------------------------
Mid (string, starting from the first, length) ByRef [string] [starting from the first] [length of string]
For example, mid ("Little Xin Invincible", 1, 3) then return to "Xiao Xin No"
InStr (starting from the first, string 1, String 2) ByVal, starting from the specified position, returns the position of String 2 in string 1
For example InStr (1, "Xiao Xin Invincible", "small") then return to 1,INSTR (2, "Little Xin Invincible", "small"), then return 0. 0 indicates not found
InStrRev (String 1, String 2, starting from the beginning) ByVal from the specified position, from the post-live lookup, return the position of string 2 in the string 1, note here, although the back-to-live lookup, but the return value is calculated from the previous.
For example InStrRev ("Xiao Xin Invincible", "small", 2) then return 2; InStrRev ("Xiao Xin Invincible", "Hin", 1) then returned 0, because it from the "Little Xin Invincible" the 1th Word to start looking forward, so can not find. 0 means not found China self-taught programming network www.zxbc.cn
Left (string, length) ByVal returns the [length] character starting from the start of [string]
For example left ("Little Hin Invincible, 3) then return to" Little Hin No "
Right (string, length) ByVal returns the [length] characters from the left of [string]
For example right ("Little Xin Invincible", 3) then return to "Hin Invincible"
UCase (String) ByVal returns the uppercase form of [string], valid only for English characters
For example, UCase ("Xiaoxinwudi") returns "Xiaoxinwudi"
LCase (String) ByVal returns the lowercase form of [string], valid only for English characters
For example, LCase ("Xiaoxinwudi") returns "Xiaoxinwudi"
ASC (character) ByVal returns the ASCII encoding of [character], if there are more than one character, only the ASCII encoding of the first character is returned, and the Chr () function is a reversible process
For example ASC ("small") returns-12127; ASC ("Little Xin Invincible") also returns-12127
Chr (ASCII encoding) Byval returns the character represented by [ASCII] encoding, and the CHR () function is a reversible process
For example Chr (-12127) returns "small" and Chr (ASC ("small")) returns "Small" (this is to illustrate the reversibility of ASC and CHR, example of which can be used to encrypt text)
Trim (String) Byval returns the [string] that was removed before and after
For example, trim ("Little Xin Invincible") back "little Xin Invincible", the middle of the space is not affected by any
String (number, character) Byval returns [number] of [characters]
For example, string (3, "small") returns "small", while string (3, "Xiao Xin Invincible") also returns "little", only the first word characters valid
Space (number) Byval return [number] of spaces
For example, Space (5) returns ""
StrConv (string, type of conversion) Byval the string to the specified type. The common type is only two, vbwide half angle turn full angle, vbnarrow turn into half angle
For example StrConv ("Xiao", vbwide) returns "Xiao", while StrConv ("Xiao", vbnarrow) returns "Xiao"
' Remarks vbwide = 4, Vbnarrow = 8
Len (String) Byval returns the length of [string]
For example Len ("Little Hin Invincible") returns 4
------------------------------------------------------------------------------------------
Len Len (string|varname) returns the number of characters in a string, or the number of bytes required to store a variable trim trim (string) to remove the spaces before and after the string Ltrim Ltrim (String) to remove the spaces in front of the string Rtrim Rtrim (String) removes the space following the string by mid mid (String,start,length) from the start character of the string string to get the length of the string, If the third argument is omitted, the string from the start character to the end of the string is left (string,length) Gets the length of the string from the side of string string right-right (String,length) String LCase LCase (string) converts all uppercase letters in a string string to lowercase letters UCase UCase (string) from the right of string string Converts all uppercase letters in string strings to uppercase letters StrComp StrComp (String1,string2[,compare]) Returns the result of a comparison between the string1 string and the string2 string, or 0 if two strings are the same. Returns 1 if it is less than 1 if it is greater than
InStr InStr (string1,string2[, compare]) returns the position of the first occurrence of the string1 string in the string2 string
Split Split (string1,delimiter[, count[, start]]) splits the string into a one-dimensional array based on delimiter, where delimiter is used to identify substring bounds. If omitted, a space ("") is used as the delimiter.
Count returns the number of substrings,-1 indicates that all substrings are returned.
Start performs a text comparison for 1, or binary comparison if it is 0 or omitted. Replace replace (expression, find, replacewith[, compare[, count[, start]]) returns a string with the specified number of substrings (find) replaced by another substring ( replacewith)
[Example:]
1. Len Function Example:
The following example uses the Len function to return the number of characters in a string:
Dim MyString
MyString = Len ("VBSCRIPT") ' MyString contains 8.
2, Trim, Ltrim, RTrim function Example:
The following example takes advantage of the LTrim, RTrim, and Trim functions, respectively, to remove whitespace, trailing space, start, and trailing spaces that begin with a string:
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 in a string starting with the fourth character:
Dim MyVar
MyVar = Mid ("VB Script is fun!", 4, 6) ' MyVar contains ' Script '.
4. Example of Left function:
The following example takes advantage of the left function to return the three letters to mystring:
Dim MyString, leftstring
MyString = "VBSCript"
Leftstring = Left (MyString, 3) ' leftstring contains ' VBS
5. The Right function example:
The following example takes advantage of the right function to return a specified number of characters from the left side of a string:
Dim AnyString, MyStr
anystring = "Hello World" defines the string.
MyStr = Right (anystring, 1) ' returns ' d '.
MyStr = Right (anystring, 6) ' Return to ' world '.
MyStr = Right (anystring, 20) ' Return to ' Hello world '.
6. LCase Function Example:
The following example uses the LCase function to convert an uppercase letter to lowercase letters:
Dim MyString
Dim lcasestring
MyString = "VBSCript"
lcasestring = LCase (MyString) ' lcasestring contains ' VBScript '.
7. UCase Function Example:
The following example uses the UCase function to return the uppercase form of a string:
Dim MyWord
MyWord = UCase ("Hello World") ' Return to ' Hello World '.
8. StrComp Function Example:
The following example uses the StrComp function to return the result of a string comparison. If the third argument is 1, the text comparison is performed, and if the third argument is 0 or omitted, the binary comparison is performed.
Dim MyStr1, MYSTR2, MyComp
MYSTR1 = "ABCD": MyStr2 = "ABCD" ' defines the variable.
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 INSTR to search for a string:
Dim searchstring, SearchChar, MyPos
SearchString = "Xxpxxpxxpxxp"???
SearchChar = "P"??
MyPos = Instr (searchstring, SearchChar)??? ' Returns 9.
Note: The character position returned is not the first occurrence of a string in another string, but a byte position.
10. Example of Split function:
Dim MyString, MyArray, MSG
MyString = "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:
Replace ("ABCD", "BC", "12") ' Get a12d
------------------------------------------------------------------------------------------------
1. Chr[$] (value) function
Returns the corresponding character of the standard extension code.
Description
(1) The values range from 0 to 255.
(2) Chr () returns a numeric type, while chr$ () returns the character type.
(3) ANSI is an extension of ASCII code, the first 128 characters are the same as the ASCII code.
For example, we often use the following statement to add a carriage return line break. Chr (10)
2. ASC ("character") function
This function is used to return the ANSI code value of a character.
Note: If the input is a string, only the ASCII value of the first character is returned.
For example
X=ASC ("a"), then, x=97
X=ASC ("AB"), then, x=97
3. String[$] (number, character)
Used to repeat a character.
Description
(1) "number" is used to specify the number of repetitions.
(2) If "character" is a string, only the first character is duplicated.
4. Len (String) function
Used to return the length of a string.
5. Left[$] (string, number of characters)
A string that returns the leftmost length of the string as the number of characters.
For example
Dim substr as String
Substr=left ("Visual Basic", 3)
The
Substr= "Vis"
6. Right[$] (string, number of characters)
A string that returns the rightmost length of the string as the number of characters.
For example
Dim substr as String
Substr=right ("Visual Basic", 3)
The
Substr= "sic"
7. Mid[$] (string, start position, [number of characters])
Used to return a substring.
Description
(1) The substring starts with "starting position" and "number of characters" as the length.
(2) If "Number of characters" is omitted, then from the starting position to the end of the string.
8. Lcase (String) and UCase (string) functions
Lcase: The output is lowercase regardless of whether the characters in the string are uppercase or lowercase.
Ucase: The output is lowercase regardless of whether the characters in the string are uppercase or lowercase.
9. Ltrim (String), Rtrim (String), Trim (string) functions
Ltrim (String): Used to remove the left-hand space in a string.
Rtrim (String): Used to remove the right-hand space in a string.
Trim (String): Used to remove the left and right spaces in a string.
10. STR (numeric) function and Val (string) function
STR (numeric): Used to convert a number to a string.
Val (String): Used to convert a string to a numeric value.
For example
Dim A as String
Dim B as Long
A=str (345.45)
B=val ("234.45")
The
A= "345.45"
b=234.45
Summary of VB string function