Replace string

4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next

version 11.1 (Modified)


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
**If passed: diacritical evaluation
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.

By default, the command is not case sensitive and does not take accented characters into account (a=A, a=à, etc.). If you pass the asterisk * as the last parameter, you indicate that the evaluation of the characters must be diacritical, in other words, it must be case sensitive and take accented characters into account (a#A, a#à...).

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);"")

3. The following example illustrates the use of the * parameter:

   vtResult:=Replace string("Crème brûlée";"Brulee";"caramel") `Result gets "Crème caramel"
   vtResult:=Replace string("Crème brûlée";"Brulee";"caramel";*) `Result gets "Crème brûlée"

See Also

Change string, Delete string, Insert string.


4D - Documentation   Français   English   German   Spanish   4D v11 SQL, Command Theme List   4D v11 SQL, Command Alphabetical List   4D v11 SQL, Constant Theme List   Back   Previous   Next