Replace first (replace)
Description
Searches for a value in a given string and returns a new string where only the first occurrence (if any) is replaced by another indicated value. Note that this operation is case sensitive.
How does it work in the search window?
Select Create column in the search window toolbar, then select the Replace first operation. You need to specify three arguments:
Argument | Data type |
---|---|
Starting string mandatory | string |
Substring to search mandatory | string |
Substring to replace mandatory | string |
The data type of the values in the new column is string.
Example
In the demo.ecommerce.data
table, we want to create a new column that replaces only the first = occurrence in all the strings of the uri column by _ . To do it, we will create a new column using the Replace first operation.
The arguments needed to create the new column are:
String - uri column
Substring to search - Click the pencil icon and enter =
Substring to replace - Click the pencil icon and enter _
Click Create column and you will see the following result:
How does it work in LINQ?
Use the operator select
... as
... and add the operation syntax to create the new column. This is the syntax for the Replace first operation:
replace(string, string_to_search, string_to_replace)
Example
You can copy the following LINQ script and try the above example on the demo.ecommerce.data
table.Â
from demo.ecommerce.data
select replace(uri, "=", "_") as `first=by_`