ASP String Functions:
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) strips the space before and after the string
Ltrim Ltrim (string) Removes the space in front of the string
Rtrim Rtrim (string) Removes the space after the string
mid mid ( String,start,length) A string of length lengths starting from the start character of the string string, if the third argument is omitted to represent the string starting from the start character to the end of the string
Left (string, Length) Gets the string length from the left of the string
right String,length a string of length from the side of string string
LCase LCase ( String) converts all uppercase letters in a string string to lowercase
UCase UCase (string) converts all uppercase letters in a string string to uppercase letters
StrComp StrComp (string1, String2[,compare]) Returns the result of a comparison between the string1 string and the string2 string, if the two string is the same, 0 is returned if it is less than 1 if it is greater than 1
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).
Add:
The ASC ASC function extracts the ANSI character code for the first letter of a string.
To use: result = ASC (string)
Where result is a character code, string is any valid string expression. If the string is empty, a real-time error is generated.
The AscB AscB function extracts the first byte of a string.
Usage: result = AscB (string)
Where result is a byte class and string is any valid string expression. If the string is empty, a real-time error is generated.
The ASCW AscW function extracts the Unicode character code for the first letter of a string.
Usage: result = ASCW (string)
Where result is unicode,string is any valid string expression. If the string is empty, a real-time error is generated.
The INSTR InStr function identifies the initial position of a tick in a string.
Usage: Newstart = INSTR ([Start,]source, token[, compare])
Where Newstart is the position of the tick in the string (0 if not), start is the starting position of the lookup, source is the string to locate, token is the string to locate, and compare is the comparison type (0 for binary comparison, 1 indicates a text comparison that ignores case).
The InStrB InStrB function is a byte version of InStr that identifies the first byte position of a tick in a string.
Usage: Newstart = InStrB ([Start,]source, token[, compare])
Where Newstart is the first byte position in the string (or 0 if not), start is the starting position of the lookup, source is the string to locate, token is the string to locate, and compare is the comparison type (0 for binary comparison, 1 indicates a text comparison that ignores case).
The LCase LCase function turns the string into lowercase.
Usage: result = LCase (string)
Where result is a lowercase string and string is any valid string expression.
The left function extracts the specified number of characters from the beginning of the string.
Usage: result = Left (string,length)
Where result is a string variable, string is a valid string expression, and length is a numeric expression that represents how many characters are returned.
The LeftB LeftB function extracts a specified number of bytes from the beginning of the string.
Usage: result = LeftB (string,length)
Where result is a string variable, string is a valid string expression, and length is a numeric expression that represents the number of bytes fetched.
The Len Len function determines the size of a string or how many characters are required to store the variable.
Usage is: result = Len (String | varname)
Where result is the number of characters in a string or the number of bytes required to store the variable, string is any valid string expression and varname is the variable name.
The LenB len function determines the size of a string or how many bytes are required to store the variable.
Usage: result = LenB (String | varname)
Where result is the number of bytes in a string or the number of bytes required to store the variable, string is any valid string expression and varname is the variable name.
LTrim the LTrim function to copy the string and remove the preceding space.
Usage: result = LTrim (string)
Where result is the string after the space is stripped, string is a valid string expression to remove the space.
The mid mid function copies a specified number of characters from a location in the string.
Usage: result = Mid (String,start[,length])
Where result is the result string, string is the expression from which to copy the character, start is the starting position of the copy in string, and length is the number of characters to copy.
The MidB mid function copies a specified number of bytes from a location in the string.
Usage: result = Mid (String,start[,length])
Where result is the result string, string is the expression from which to copy the Byte, start is the starting position of the copy in string, and length is the number of bytes to copy.
The right-right function extracts the specified number of characters from the end of the string.
To use: result = Right (String,length)
Where result is a string variable, string is a valid string expression, and length is a numeric expression that represents how many characters are returned.
The RightB RightB function extracts a specified number of bytes from the beginning of the string.
Usage: result = RightB (string,length)
Where result is a string variable, string is a valid string expression, and length is a numeric expression that represents the number of bytes fetched.
RTrim the RTrim function to copy the string and remove the trailing space.
Usage: result = RTrim (string)
Where result is the string after the space is stripped, string is a valid string expression to remove the space.
The string string function constructs a string that contains multiple identical characters.
Usage is: result = String (number, character)
Where result is a string variable, number is the length of the returned string, and character is the character code used to construct the returned string.
The Trim Trim function copies the string and removes the leading and trailing spaces.
Usage is: result = Trim (string)
Where result is the string after the space is stripped, string is a valid string expression to remove the space.
The UCase UCase function turns the string into uppercase.
Usage: result = UCase (string)
Where result is an uppercase string, string is any valid string expression.
ASP string functions [discussion]
Function description
CBool
Data to Boolean type
Cdate
Data transfer Time Type
CDbl
Data transfer Double Type
Cint
Data to Integer type
CLng
Data transfer to Lang type
Asc
Character to number type
Cstr
Number to String type
Chr
Numeric to character type
Variant variables typically automatically convert the data subtype they represent to the appropriate data type, but sometimes automatic conversions can also cause some data type mismatch errors. At this point, you can use a transform function to cast the subtype of the data.
function function
The ASC function returns an ANSI character code corresponding to the first letter of a string.
The CHR function returns the character corresponding to the specified ANSI character code
The hex function returns a string representing a hexadecimal numeric value.
The OCT function returns a String that represents the octal value of a number.
The CSTR function returns an expression that has been converted to a string subtype.
The CDate function returns an expression that has been converted to a date subtype.
The CInt function returns an expression that has been converted to an integer subtype.
The CLng function returns an expression that has been converted to a long integer sub-type
The CSng function returns an expression that has been converted to a single sub-type
The CDBL function returns an expression that has been converted to a Double subtype
The CBool function returns an expression that has been converted to the Bourg type
1. Examples of ASC functions
In the following example, ASC returns the ANSI character code for each of the first letters of the string:
Dim MyNumber
MyNumber = ASC ("A") ' returns 65.
MyNumber = ASC ("a") ' returns 97.
MyNumber = ASC ("Apple") ' returns 65.
2. Chr Function Example
The following example uses the CHR function to return the character corresponding to the specified character code:
Dim MyChar
MyChar = CHR (65) ' returns A.
MyChar = CHR (97) ' Returns a.
MyChar = CHR (62) ' Return to >.
MyChar = Chr (37) ' returns%.
3. Hex Function Example
The following example uses the Hex function to return the hexadecimal number of a number:
Dim Myhex
Myhex = Hex (5) ' returns 5.
Myhex = Hex (10) ' Returns a.
Myhex = Hex (459) ' returns 1CB.
4. Oct Function Example
The following example uses the OCT function to return the octal number of a numeric value:
Dim myoct
Myoct = Oct (4) ' returns 4.
MYOCT = Oct (8) ' returns 10.
Myoct = Oct (459) ' returns 713.
5. CStr Function Example
<%num1=666strwelcome= "Welcome" &CSTR (NUM1) & "visitors"%>
CStr to cast a variable num1 from an integer subtype to a string subtype
6. CDate Function Example
MyDate = "October 19, 1962" ' defines the date.
Myshortdate = CDate (mydate) ' is converted to a date data type.
MyTime = "4:35:47 PM" ' defines the time.
Myshorttime = CDate (MyTime) ' is converted to a date data type.
7. CInt Function Example
Dim MyDouble, MyInt
MyDouble = 2345.5678 ' MyDouble is Double.
MyInt = CInt (mydouble) ' MyInt contains 2346.
8. CLng Function Example
Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45:myval2 = 25427.55 ' MyVal1, MyVal2 is a double-precision value.
MyLong1 = CLng (MyVal1) ' MyLong1 25427.
MyLong2 = CLng (MyVal2) ' MyLong2 contains 25428.
9. CBool Function Example
Dim A, B, Check
A = 5:b = 5 ' initializes the variable.
Check = CBool (A = B) ' checkbox set to True.
A = 0 ' defines the variable.
Check = CBool (A) ' checkbox set to False