Siebel VB Language Reference > VB Language Reference >
Mid Statement
Mid replaces part (or all) of one string with another, starting at a specified location. Syntax
Mid (stringVar, start[, length]) = string
|
|
stringVar |
The string to be changed |
start |
An integer representing the position in stringVar at which to begin replacing characters |
length |
An integer representing the number of characters to replace |
string |
The string to place into stringVar |
Returns
The value of stringVar with string embedded at the specified location. Usage
If the length argument is omitted, or if there are fewer characters in string than specified in length, then Mid replaces the characters from the start to the end of the string. If start is larger than the number of characters in the indicated stringVar, then Mid appends string to stringVar. If length is greater than the length of string, then length is set to the length of string. If start is greater than the number of characters in stringVar, an illegal function call error occurs at runtime. If length plus start is greater than the length of stringVar, then only the characters up to the end of stringVar are replaced. Mid never changes the number of characters in stringVar. The index of the first character in a string is 1. Example
This example uses the Mid statement to replace the last name in a user-entered string with asterisks (*). Sub Button_Click Dim username as String Dim position as Integer Dim count as Integer Dim uname as String Dim replacement as String username = "Chris Smith" uname = username replacement = "*" Do position = InStr(username," ") If position = 0 then Exit Do End If username = Mid(username,position + 1) count = count + position Loop For x = 1 to Len(username) count = count + 1 Mid(uname,count) = replacement Next x End Sub
Related Topics
LCase Function Left Function Len Function LTrim Function Mid Statement Right Function RTrim Function Trim Function
|