Siebel VB Language Reference > VB Language Reference >
Mid Function
This standard VB function returns a portion of a string, starting at a specified location within the string. Syntax
Mid[$](string, start[, length])
|
|
string |
A string or string expression containing the string to be copied |
start |
An integer representing the starting position in string to begin copying characters |
length |
An integer representing the number of characters to copy |
Returns
A substring of string, of length length, beginning at the start character of string. Usage
Mid accepts any type of string, including numeric values, and converts the input value to a string. If the length argument is omitted or if string is smaller than length, then Mid returns computer characters in string. If start is larger than string, then Mid returns a null string (""). The index of the first character in a string is 1. The dollar sign ($) in the function name is optional. If it is included, the return type is string. Otherwise the function typically returns a variant of vartype 8 (string). If the value of string is Null, a variant of vartype 1 (Null) is returned. Mid$ requires the string argument to be of type string or variant. Mid allows the string argument to be of any data type. To modify a portion of a string value, read Mid Statement. Example
This example uses the Mid function to find the last name in a string entered by the user. Sub Button_Click Dim username as String Dim position as Integer username = "Chris Smith" Do position = InStr(username," ") If position = 0 then Exit Do End If position = position + 1 username = Mid(username,position) Loop End Sub
Related Topics
Left Function Len Function LTrim Function Mid Function Right Function RTrim Function Trim Function
|