version 3
Replace string (source; oldString; newString{; howMany}) String
Parameter | Type | Description | |
source | String | Original string | |
oldString | String | Characters to replace | |
newString | String | Replacement string | |
(if empty string, occurrences are deleted) | |||
howMany | Number | How many times to replace | |
If omitted, all occurrences are replaced | |||
Function result | String | Resulting string |
Description
Replace string replaces howMany occurrences of oldString in source with newString.
If newString is an empty string (""), Replace string deletes each occurrence of oldString in source.
If howMany is specified, Replace string will replace only the number of occurrences of oldString specified, starting at the first character of source. If howMany is not specified, then all occurrences of oldString are replaced.
If oldString is an empty string, Replace string returns the unchanged source.
Examples
1. The following example illustrates the use of Replace string. The results, described in the comments, are assigned to the variable vtResult.
vtResult:=Replace string("Willow";" ll";"d") ` Result gets "Widow" vtResult:=Replace string("Shout"; "o";"") ` Result gets "Shut" vtResult:=Replace string(vtOtherVar;Char(9);",") ` Replaces all tabs in vtOtherVar with commas
2. The following example eliminates CRs and TABs from the text in vtResult:
vtResult:=Replace string(Replace string(vtResult;Char(13);"");Char(9);"")
See Also
Change string, Delete string, Insert string.