Replace: Difference between revisions
Line 3: | Line 3: | ||
== Description == | == Description == | ||
Replace returns a string which has had one substring replaced by another a specified number of times. The required parameter, ''target'', is a string expression containing the substring to replace. The required parameter, ''find'', is the string expression to be replaced. The required parameter, ''source'', is the string expression used as the replacement. The optional parameter, ''start'', is a numeric expression that specifies the starting position of the search within the target string; if ''start'' is not provided, the search defaults to 1, which represents the first character position. The optional parameter, ''count'', is a numeric expression that specifies the number of substitutions to perform; if count is not provided -1 is used and all possible substitutions are made. The optional parameter, ''compare'', is used to specify the type of search performed. | Replace returns a string which has had one substring replaced by another a specified number of times. The required parameter, ''target'', is a string expression containing the substring to replace. The required parameter, ''find'', is the string expression to be replaced. The required parameter, ''source'', is the string expression used as the replacement. The optional parameter, ''start'', is a numeric expression that specifies the starting position of the search within the target string; if ''start'' is not provided, the search defaults to 1, which represents the first character position. The optional parameter, ''count'', is a numeric expression that specifies the number of substitutions to perform; if count is not provided -1 is used and all possible substitutions are made. The optional parameter, ''compare'', is used to specify the type of search performed. | ||
'''Table: Comparison constants''' | |||
{| class="wikitable" | |||
|- | |||
! Constant !! Value !! Description | |||
|- | |||
| vbBinaryCompare || 0 || Binary comparison case sensitive (default) | |||
|- | |||
| vbTextCompare || 1 || Textual comparison, case insensitive | |||
|} | |||
== Example == | == Example == |
Revision as of 11:49, 9 October 2012
Replace(target, find, source[, start[, count[, compare]]])
Description
Replace returns a string which has had one substring replaced by another a specified number of times. The required parameter, target, is a string expression containing the substring to replace. The required parameter, find, is the string expression to be replaced. The required parameter, source, is the string expression used as the replacement. The optional parameter, start, is a numeric expression that specifies the starting position of the search within the target string; if start is not provided, the search defaults to 1, which represents the first character position. The optional parameter, count, is a numeric expression that specifies the number of substitutions to perform; if count is not provided -1 is used and all possible substitutions are made. The optional parameter, compare, is used to specify the type of search performed.
Table: Comparison constants
Constant | Value | Description |
---|---|---|
vbBinaryCompare | 0 | Binary comparison case sensitive (default) |
vbTextCompare | 1 | Textual comparison, case insensitive |
Example
Rem Replace Example 'Replace performs string substitutions Dim Message, Ride Message = "Good morning, class." Print Message Message = Replace(Message, "morning", "afternoon") Print Message Ride = "big Al's big boat ride" Ride = Replace(Ride, "big", "Big", 1, 1) Print Ride
Output
Good morning, class. Good afternoon, class. Big Al's big boat ride