Replace string

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 3


Replace string (source; oldString; newString{; howMany}) String

ParameterTypeDescription
sourceStringOriginal string
oldStringStringCharacters to replace
newStringStringReplacement string
(if empty string, occurrences are deleted)
howManyNumberHow many times to replace
If omitted, all occurrences are replaced
Function resultStringResulting 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.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next