String pattern replacement: replace
Syntax
replace ( op , pattern1, pattern2 )
Input parameters
op |
the operand |
pattern1 |
the pattern to be replaced |
pattern2 |
the replacing pattern |
Examples of valid syntaxes
replace(DS_1, "Hello", "Hi")
replace(DS_1, "Hello")
Semantics for scalar operations
Replaces all the occurrences of a specified string-pattern (pattern1) with another one (pattern2). If pattern2 is omitted then all occurrences of pattern1 are removed. For example:
replace("Hello world", "Hello", "Hi")
gives "Hi world"
replace("Hello world", "Hello")
gives " world"
replace ("Hello", "ello", "i")
gives "Hi"
Input parameters type
op
dataset { measure<string> _+ }
| component<string>
| string
pattern1, pattern2
component<string>
| string
Result type
result
dataset { measure<string> _+ }
| component<string>
| string
Additional Constraints
The second parameter (pattern1) cannot be omitted.
Behaviour
As for the invocations at Data Set level, the operator has the behaviour of the “Operators applicable on one Scalar Value or Data Set or Data Set Component”. As for the invocations at Component or Scalar level, the operator has the behaviour of the “Operators applicable on more than two Scalar Values or Data Set Components” (see the section “Typical behaviours of the ML Operators”).
Examples
Given the operand dataset DS_1:
Input DS_1 (see structure)
Id_1 |
Id_2 |
Me_1 |
---|---|---|
1 |
A |
hello world |
2 |
A |
say hello |
3 |
A |
he |
4 |
A |
hello! |
Example 1
DS_r := replace (DS_1,"ello","i");
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
---|---|---|
1 |
A |
hi world |
2 |
A |
say hi |
3 |
A |
he |
4 |
A |
hi! |
Example 2
DS_r := DS_1[ calc Me_2:= replace (Me_1,"ello","i")];
results in (see structure):
Id_1 |
Id_2 |
Me_1 |
Me_2 |
---|---|---|---|
1 |
A |
hello world |
hi world |
2 |
A |
say hello |
say hi |
3 |
A |
he |
he |
4 |
A |
hello! |
hi! |