4D v14.3Replace string |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
Replace string
|
Replace string ( source ; oldString ; newString {; howMany}{; *} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
source | String |
![]() |
Original string | |||||
oldString | String |
![]() |
Characters to replace | |||||
newString | String |
![]() |
Replacement string (if empty string, occurrences are deleted) | |||||
howMany | Longint |
![]() |
How many times to replace If omitted, all occurrences are replaced | |||||
* | Operator |
![]() |
If passed: evaluation based on character codes | |||||
Function result | String |
![]() |
Resulting string | |||||
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 stringwill 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 makes global comparisons that take linguistic particularities and letters that may be written with one or more characters (for example æ = ae) into account. On the other hand, it is not diacritical (a=A, a=à and so on) and does not take "ignorable" characters such as characters whose code < 9 into account (Unicode specification).
To modify this functioning, pass the asterisk * as the last parameter. In this case, comparisons will be based on character codes. You must pass the * parameter:
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(Tab);",";*) ` Replaces all tabs in vtOtherVar with commas
The following example eliminates CRs and TABs from the text in vtResult:
vtResult:=Replace string(Replace string(vtResult;Char(Carriage return);"";*);Char(Tab);"";*)
The following example illustrates the use of the * parameter in the case of a diacritical evaluation:
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"
Product: 4D
Theme: String
Number:
233
Modified: 4D v11 SQL Release 1
Change string
Delete string
Insert string
4D Language Reference ( 4D v12.4)
4D Language Reference ( 4D v11 SQL Release 6)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)